놀코에 오신 것을 환영합니다.

놀아보자 코드랑

KOSTA/SpringBoot

Spring Boot - Mybatis 설정

놀코 2021. 8. 3. 12:33

root-context.xml 사용 안하고, 자바 @configuration 사용함.

application.properties 파일

server.port=9999
server.servlet.context-path=/dmmybatis

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp


#hikari CP -- SPRING BOOT에 이미 포함된 라이브러리

spring.datasource.hikari.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.hikari.jdbc-url=jdbc:log4jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.hikari.username=hr
spring.datasource.hikari.password=hr

spring.datasource.hikari.maximum-pool-size=10

DatabaseConfiguration.java 파일

package com.example.demo.configuration;

import javax.sql.DataSource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

@Configuration
@PropertySource("classpath:/application.properties")
public class DatabaseConfiguration {
	
	@Bean
	@ConfigurationProperties(prefix="spring.datasource.hikari")
	public HikariConfig hikariConfig() {
		return new HikariConfig();
	}
	@Bean	
	public DataSource dataSource() throws Exception {
		DataSource dataSource = new HikariDataSource(hikariConfig());
		System.out.println(dataSource.toString());
		return dataSource;
	}

	}

 

상위 SpringBootApplication에서는 하위 폴더들을 ComponentScan

다른경로의 경우에는 꼭 @ComponentScan 어노테이션 경로를 설정해줘야함.

JSP사용 할때는 마켓플레이스에서 Eclipse Enterprise java and Web Developer Tools 설치하자