참고 깃허브
sqlSessionFactory 설정 및 Qualifier 설정
package com.day.boardrest.configuration;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
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;
}
@Autowired
private ApplicationContext applicationContext;
@Bean
@Qualifier("UnderscoreToCamelCase")
public SqlSessionFactory sqlSessionFactory1(DataSource dataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setConfigLocation(applicationContext.getResource("classpath:/mybatisConfig/mybatis-board-config.xml"));
return sqlSessionFactoryBean.getObject();
}
@Bean
@Qualifier("Underscore")
public SqlSessionFactory sqlSessionFactory2(DataSource dataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setConfigLocation(applicationContext.getResource("classpath:/mybatisConfig/mybatis-config.xml"));
return sqlSessionFactoryBean.getObject();
}
@Bean
@Qualifier("UnderscoreToCamelCaseTemplate")
public SqlSessionTemplate sqlSessionTemplate1(DataSource dataSource) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory1(dataSource));
}
@Bean
@Qualifier("UnderscoreTemplate")
public SqlSessionTemplate sqlSessionTemplate2(DataSource dataSource) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory2(dataSource));
}
}
JPA
@id (pk역할)
@Column(name="컬럼명")
@Transient - 영속성 무시, 비번의 경우 보완 노출 때문에..
'KOSTA > SpringBoot' 카테고리의 다른 글
Spring Boot에서 CORS 적용해보기 (0) | 2021.08.13 |
---|---|
cascade , mappedBy, fetch (0) | 2021.08.12 |
SpringBoot - JPA(2) (0) | 2021.08.05 |
Spring Boot - Mybatis 설정 (0) | 2021.08.03 |
STS 설치 및 설정, Junit5, Logger(logback) 설정 (0) | 2021.08.02 |