일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- node 이미지 저장
- set foreign_key
- MySQL
- 리플리케이션 오류
- 워드프레스한글팩
- openfire
- 훼인
- 앞으로 가기
- ssmtp
- 특정 패키지 업데이트 중지 / 해제
- 날짜계산
- 쁘띠프랑스
- 중독 게임
- 재귀쿼리
- 이미지주소추출
- quota
- php-fpm
- node.js
- rsync
- mongodb
- php
- 태권브이
- simplexml_load_filesimplexml
- 뒤로 가기
- security.limit_extensions
- no key alg
- 태권v
- strtotime
- xcache
- 외래키
- Today
- Total
일상 기록 창고
@Configuration 과 @Bean 을 이용한 설정2 본문
import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import net.sf.log4jdbc.Log4jdbcProxyDataSource; import net.sf.log4jdbc.tools.Log4JdbcCustomFormatter; import net.sf.log4jdbc.tools.LoggingType; @Configuration public class DbConfig {
@Bean(destroyMethod="close") public DataSource dataSourceLog(){ BasicDataSource dataSourceLog = new BasicDataSource();
dataSourceLog.setDriverClassName("org.mariadb.jdbc.Driver"); dataSourceLog.setUrl("jdbc:mariadb://localhost/test"); dataSourceLog.setUsername("test"); dataSourceLog.setPassword("test"); dataSourceLog.setValidationQuery("select 1"); dataSourceLog.setTestOnBorrow(true); dataSourceLog.setTestWhileIdle(true); dataSourceLog.setTimeBetweenEvictionRunsMillis(130000);
return dataSourceLog; }
@Bean public Log4jdbcProxyDataSource dataSource( DataSource dataSourceLog ) { Log4JdbcCustomFormatter formatter = new Log4JdbcCustomFormatter(); formatter.setLoggingType(LoggingType.MULTI_LINE); formatter.setSqlPrefix("SQL : \n");
Log4jdbcProxyDataSource dSource = new Log4jdbcProxyDataSource(dataSourceLog); return dSource; }
@Bean public SqlSessionFactory sqlSessionFactory( Log4jdbcProxyDataSource dataSource, ApplicationContext applicationContext )throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); sessionFactory.setConfigLocation(applicationContext.getResource("classpath:mybatis-config.xml")); sessionFactory.setMapperLocations( new PathMatchingResourcePatternResolver().getResources("classpath:mappers/**Mapper.xml") ); return (SqlSessionFactory) sessionFactory.getObject(); }
@Bean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) throws Exception { SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory); return sqlSessionTemplate; } } |
'프로그래밍 > Spring (jsp)' 카테고리의 다른 글
RequestMapping 여러개 사용 시 (0) | 2017.04.19 |
---|---|
org.mariadb.jdbc.internal.util.dao.QueryException: Could not read resultset: unexpected end of stream, read 0 bytes from 4 (0) | 2017.03.07 |
@Configuration 과 @Bean 을 이용한 설정1 (0) | 2017.03.06 |
파일업로드 시 했던 일... (0) | 2017.02.14 |
JSON 파싱하기 (0) | 2017.02.14 |