|
|
@ -1,11 +1,11 @@ |
|
|
|
package org.pqh.core.config; |
|
|
|
package org.pqh.core.config; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.druid.pool.DruidDataSource; |
|
|
|
import org.apache.commons.dbcp2.BasicDataSource; |
|
|
|
import org.apache.commons.dbcp2.BasicDataSource; |
|
|
|
import org.pqh.core.util.LogManger; |
|
|
|
import org.pqh.core.util.LogManger; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
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; |
|
|
@ -19,14 +19,9 @@ 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 implements LogManger{ |
|
|
|
public class HibernateConfig implements LogManger{ |
|
|
|
|
|
|
|
|
|
|
|
@Value("${hibernate.connection.pool_size}") |
|
|
|
|
|
|
|
private String pool_size; |
|
|
|
|
|
|
|
@Value("${hibernate.jdbc.fetch_size}") |
|
|
|
|
|
|
|
private String fetch_size; |
|
|
|
|
|
|
|
@Value("${hibernate.dialect}") |
|
|
|
@Value("${hibernate.dialect}") |
|
|
|
private String dialect; |
|
|
|
private String dialect; |
|
|
|
@Value("${hibernate.connection.driver_class}") |
|
|
|
@Value("${hibernate.connection.driver_class}") |
|
|
@ -37,6 +32,8 @@ public class HibernateConfig implements LogManger{ |
|
|
|
private String username; |
|
|
|
private String username; |
|
|
|
@Value("${hibernate.connection.password}") |
|
|
|
@Value("${hibernate.connection.password}") |
|
|
|
private String password; |
|
|
|
private String password; |
|
|
|
|
|
|
|
@Value("${sessionFactory.scan:org.pqh.core.model}") |
|
|
|
|
|
|
|
private String packagesToScan[]; |
|
|
|
|
|
|
|
|
|
|
|
private LocalSessionFactoryBean sessionFactoryBean; |
|
|
|
private LocalSessionFactoryBean sessionFactoryBean; |
|
|
|
|
|
|
|
|
|
|
@ -49,16 +46,24 @@ public class HibernateConfig implements LogManger{ |
|
|
|
return dataSource; |
|
|
|
return dataSource; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DruidDataSource druidDataSource(){ |
|
|
|
|
|
|
|
DruidDataSource dataSource=new DruidDataSource(); |
|
|
|
|
|
|
|
dataSource.setUrl(url); |
|
|
|
|
|
|
|
dataSource.setUsername(username); |
|
|
|
|
|
|
|
dataSource.setPassword(password); |
|
|
|
|
|
|
|
dataSource.setDriverClassName(driver); |
|
|
|
|
|
|
|
return dataSource; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
@PostConstruct |
|
|
|
public void init() throws IOException { |
|
|
|
public void init() throws IOException { |
|
|
|
log.info("数据库配置初始化\nurl="+url+"\nusername="+username+"\npassword="+password); |
|
|
|
log.info("数据库配置初始化\nurl="+url+"\nusername="+username+"\npassword="+password); |
|
|
|
sessionFactoryBean=new LocalSessionFactoryBean(); |
|
|
|
sessionFactoryBean=new LocalSessionFactoryBean(); |
|
|
|
Properties properties=new Properties(); |
|
|
|
Properties properties=new Properties(); |
|
|
|
properties.setProperty("hibernate.connection.pool_size",pool_size); |
|
|
|
|
|
|
|
properties.setProperty("hibernate.jdbc.fetch_size",fetch_size); |
|
|
|
|
|
|
|
properties.setProperty("hibernate.dialect",dialect); |
|
|
|
properties.setProperty("hibernate.dialect",dialect); |
|
|
|
sessionFactoryBean.setDataSource(basicDataSource()); |
|
|
|
sessionFactoryBean.setHibernateProperties(properties); |
|
|
|
sessionFactoryBean.setPackagesToScan("org.pqh.core.model"); |
|
|
|
sessionFactoryBean.setDataSource(druidDataSource()); |
|
|
|
|
|
|
|
sessionFactoryBean.setPackagesToScan(packagesToScan); |
|
|
|
sessionFactoryBean.afterPropertiesSet(); |
|
|
|
sessionFactoryBean.afterPropertiesSet(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|