|
|
@ -1,9 +1,13 @@ |
|
|
|
package org.pqh.core.config; |
|
|
|
package org.pqh.core.config; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.dbcp2.BasicDataSource; |
|
|
|
import org.apache.commons.dbcp2.BasicDataSource; |
|
|
|
|
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
|
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
import org.pqh.core.util.PropertiesUtil; |
|
|
|
import org.pqh.core.util.PropertiesUtil; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
|
|
|
import org.springframework.context.annotation.PropertySource; |
|
|
|
import org.springframework.orm.hibernate5.HibernateTemplate; |
|
|
|
import org.springframework.orm.hibernate5.HibernateTemplate; |
|
|
|
import org.springframework.orm.hibernate5.HibernateTransactionManager; |
|
|
|
import org.springframework.orm.hibernate5.HibernateTransactionManager; |
|
|
|
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; |
|
|
|
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; |
|
|
@ -16,19 +20,24 @@ import java.util.Properties; |
|
|
|
* Created by reborn on 2017/7/28. |
|
|
|
* Created by reborn on 2017/7/28. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
|
|
|
|
@PropertySource("classpath:config.properties") |
|
|
|
@EnableTransactionManagement |
|
|
|
@EnableTransactionManagement |
|
|
|
public class HibernateConfig { |
|
|
|
public class HibernateConfig { |
|
|
|
|
|
|
|
|
|
|
|
private LocalSessionFactoryBean sessionFactoryBean; |
|
|
|
private LocalSessionFactoryBean sessionFactoryBean; |
|
|
|
private BasicDataSource dataSource; |
|
|
|
private BasicDataSource dataSource; |
|
|
|
Properties properties = PropertiesUtil.loadPropertiesFromResourceFile("config.properties"); |
|
|
|
private Logger log= LogManager.getLogger(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${dbcp2.url}") |
|
|
|
|
|
|
|
private String url; |
|
|
|
|
|
|
|
@Value("${dbcp2.username}") |
|
|
|
|
|
|
|
private String username; |
|
|
|
|
|
|
|
@Value("${dbcp2.password}") |
|
|
|
|
|
|
|
private String password; |
|
|
|
|
|
|
|
|
|
|
|
public HibernateConfig() { |
|
|
|
public HibernateConfig() { |
|
|
|
|
|
|
|
log.info("数据库配置初始化\ndburl="+url+",dbcp2.username="+username+",dbcp2.password="+password); |
|
|
|
dataSource = new BasicDataSource(); |
|
|
|
dataSource = new BasicDataSource(); |
|
|
|
dataSource.setUrl(properties.getProperty("dbcp2.url")); |
|
|
|
|
|
|
|
dataSource.setUsername(properties.getProperty("dbcp2.username")); |
|
|
|
|
|
|
|
dataSource.setPassword(properties.getProperty("dbcp2.password")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); |
|
|
|
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); |
|
|
|
sessionFactoryBean = new LocalSessionFactoryBean(); |
|
|
|
sessionFactoryBean = new LocalSessionFactoryBean(); |
|
|
|
sessionFactoryBean.setDataSource(dataSource); |
|
|
|
sessionFactoryBean.setDataSource(dataSource); |