목차 돌아가기

Spring 커넥션풀
데이터베이스 연결을 미리 준비해 놓고 사용하는 방법
25-1 c3p0 모듈의 CombopolledDataSource
   
'c3p0'를 이용해서 dataSource에 db정보를 set 해준다.
25-2 스프링 설정파이를 이용한 DataSource 설정
   
스프링 설정파일을 통해서 dataSource를 저장한다.
new를 선언하는 방식(bean 등록x)
//1. dataSource 선언
private ComboPooledDataSource dataSource;
//2. new
dataSource = new ComboPooledDataSource();
//3. db정보 set
dataSource..setDirver(driver);
dataSource.setJdbcUrl(url);
dataSource.setUser(userId);...
//4. template 연동
template = new JdbcTemplate();
template.setDataSource(dataSource);
bean 등록(servlet-context.xml) -> 객체 @AutoWired(권장)
<!-- bean 등록 -->
<beans:bean id ="dataSource" class="com.hchange.v2.c3p0.ComPooledDataSource">
	<beans:property name="dirverClass" value="oracle..."/>
...
</beans>
@Autowired
public MenberDao(ComboPooledDataSource dataSource){
	this,template = new JdbcTemplate(dataSource);
}
Config 방법 -> @Autowired (권장)
@Configuration
public class DBconfig { 
	
    @Bean
    public ComPooledDataSource dataSource() throws PropertyVetoExcetion(){
    ComPooledDataSource dataSource = new ComPooledDataSource();
    
    dataSource.setDriver("oracle...");
    ...
    return dataSource;
}

'Spring > [인프런] Spring FrameWork' 카테고리의 다른 글

DI(Dependency injection)  (0) 2022.01.24
Spring AOP 개념  (0) 2022.01.21
Spring JDBC 연동 & JDBC Template  (0) 2022.01.08
리다이렉트, 인터셉트  (0) 2022.01.06
세션, 쿠키  (0) 2022.01.03

+ Recent posts