|
|
|
@ -14,25 +14,32 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Created by reborn on 2017/7/28. |
|
|
|
|
*/ |
|
|
|
|
@Configuration |
|
|
|
|
@PropertySource("classpath:hibernate.properties") |
|
|
|
|
@PropertySource("classpath:config.properties") |
|
|
|
|
@EnableTransactionManagement |
|
|
|
|
public class HibernateConfig{ |
|
|
|
|
|
|
|
|
|
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}") |
|
|
|
|
private String url; |
|
|
|
|
@Value("${hibernate.connection.username}") |
|
|
|
|
private String username; |
|
|
|
|
@Value("${hibernate.connection.password}") |
|
|
|
|
private String password; |
|
|
|
|
@Value("${hibernate.connection.driver_class}") |
|
|
|
|
private String driver; |
|
|
|
|
|
|
|
|
|
private LocalSessionFactoryBean sessionFactoryBean; |
|
|
|
|
|
|
|
|
@ -49,9 +56,14 @@ public class HibernateConfig{ |
|
|
|
|
public void init() throws IOException { |
|
|
|
|
log.info("数据库配置初始化\nurl="+url+"\nusername="+username+"\npassword="+password); |
|
|
|
|
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.setPackagesToScan("org.pqh.core.model"); |
|
|
|
|
sessionFactoryBean.afterPropertiesSet(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Bean("transactionManager") |
|
|
|
|