parent
233492a660
commit
2593161415
@ -0,0 +1,82 @@
|
|||||||
|
package com.monkeyk.sos.config;
|
||||||
|
|
||||||
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2016/4/4
|
||||||
|
* <p/>
|
||||||
|
* Replace context.xml, transaction.xml
|
||||||
|
*
|
||||||
|
* @author Shengzhao Li
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan(basePackages = "com.monkeyk.sos")
|
||||||
|
@PropertySource(value = {"classpath:spring-oauth-server.properties"})
|
||||||
|
@EnableTransactionManagement()
|
||||||
|
public class ContextConfigurer {
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||||
|
return new PropertySourcesPlaceholderConfigurer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Value("${jdbc.driverClassName}")
|
||||||
|
private String driverClassName;
|
||||||
|
|
||||||
|
@Value("${jdbc.url}")
|
||||||
|
private String jdbcUrl;
|
||||||
|
|
||||||
|
@Value("${jdbc.username}")
|
||||||
|
private String jdbcUsername;
|
||||||
|
|
||||||
|
@Value("${jdbc.password}")
|
||||||
|
private String jdbcPassword;
|
||||||
|
|
||||||
|
@Bean(name = "dataSource")
|
||||||
|
public DataSource dataSource() {
|
||||||
|
BasicDataSource dataSource = new BasicDataSource();
|
||||||
|
dataSource.setDriverClassName(driverClassName);
|
||||||
|
dataSource.setUrl(jdbcUrl);
|
||||||
|
dataSource.setUsername(jdbcUsername);
|
||||||
|
dataSource.setPassword(jdbcPassword);
|
||||||
|
|
||||||
|
dataSource.setValidationQuery("SELECT 1");
|
||||||
|
dataSource.setTestOnReturn(false);
|
||||||
|
dataSource.setTestOnBorrow(true);
|
||||||
|
|
||||||
|
dataSource.setMaxActive(20);
|
||||||
|
dataSource.setMaxIdle(5);
|
||||||
|
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(name = "transactionManager")
|
||||||
|
public PlatformTransactionManager transactionManager(DataSource dataSource) {
|
||||||
|
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
|
||||||
|
transactionManager.setDataSource(dataSource);
|
||||||
|
return transactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(name = "jdbcTemplate")
|
||||||
|
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||||
|
return new JdbcTemplate(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue