|
|
@ -14,25 +14,32 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by reborn on 2017/7/28. |
|
|
|
* Created by reborn on 2017/7/28. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@PropertySource("classpath:hibernate.properties") |
|
|
|
@PropertySource("classpath:config.properties") |
|
|
|
@EnableTransactionManagement |
|
|
|
@EnableTransactionManagement |
|
|
|
public class HibernateConfig{ |
|
|
|
public class HibernateConfig{ |
|
|
|
|
|
|
|
|
|
|
|
private Logger log= LogManager.getLogger(); |
|
|
|
private Logger log= LogManager.getLogger(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${hibernate.connection.pool_size}") |
|
|
|
|
|
|
|
private String pool_size; |
|
|
|
|
|
|
|
@Value("${hibernate.jdbc.fetch_size}") |
|
|
|
|
|
|
|
private String fetch_size; |
|
|
|
|
|
|
|
@Value("${hibernate.dialect}") |
|
|
|
|
|
|
|
private String dialect; |
|
|
|
|
|
|
|
@Value("${hibernate.connection.driver_class}") |
|
|
|
|
|
|
|
private String driver; |
|
|
|
@Value("${hibernate.connection.url}") |
|
|
|
@Value("${hibernate.connection.url}") |
|
|
|
private String url; |
|
|
|
private String url; |
|
|
|
@Value("${hibernate.connection.username}") |
|
|
|
@Value("${hibernate.connection.username}") |
|
|
|
private String username; |
|
|
|
private String username; |
|
|
|
@Value("${hibernate.connection.password}") |
|
|
|
@Value("${hibernate.connection.password}") |
|
|
|
private String password; |
|
|
|
private String password; |
|
|
|
@Value("${hibernate.connection.driver_class}") |
|
|
|
|
|
|
|
private String driver; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private LocalSessionFactoryBean sessionFactoryBean; |
|
|
|
private LocalSessionFactoryBean sessionFactoryBean; |
|
|
|
|
|
|
|
|
|
|
@ -49,9 +56,14 @@ public class HibernateConfig{ |
|
|
|
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.setProperty("hibernate.connection.pool_size",pool_size); |
|
|
|
|
|
|
|
properties.setProperty("hibernate.jdbc.fetch_size",fetch_size); |
|
|
|
|
|
|
|
properties.setProperty("hibernate.dialect",dialect); |
|
|
|
sessionFactoryBean.setDataSource(basicDataSource()); |
|
|
|
sessionFactoryBean.setDataSource(basicDataSource()); |
|
|
|
sessionFactoryBean.setPackagesToScan("org.pqh.core.model"); |
|
|
|
sessionFactoryBean.setPackagesToScan("org.pqh.core.model"); |
|
|
|
sessionFactoryBean.afterPropertiesSet(); |
|
|
|
sessionFactoryBean.afterPropertiesSet(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean("transactionManager") |
|
|
|
@Bean("transactionManager") |
|
|
|