瞎几把改

master
luffy9412 7 years ago
parent 6ee0176bd7
commit d205830b18
  1. 2
      core/src/main/java/org/pqh/core/annotation/EnableWebCrawlerConfiguration.java
  2. 28
      core/src/main/java/org/pqh/core/config/HibernateConfig.java
  3. 4
      web/src/main/java/org/pqh/achieve/config/SpringConfig.java

@ -12,6 +12,6 @@ import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Documented
@Configuration
@ComponentScan("org.pqh.core.*")
@ComponentScan("org.pqh.core")
public @interface EnableWebCrawlerConfiguration {
}

@ -12,7 +12,7 @@ import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.io.IOException;
import javax.annotation.PostConstruct;
import java.util.Properties;
/**
@ -21,9 +21,9 @@ import java.util.Properties;
@Configuration
@PropertySource("classpath:config.properties")
@EnableTransactionManagement
public class HibernateConfig {
public class HibernateConfig extends LocalSessionFactoryBean{
private LocalSessionFactoryBean sessionFactoryBean;
private BasicDataSource dataSource;
private Logger log= LogManager.getLogger();
@ -34,36 +34,34 @@ public class HibernateConfig {
@Value("${dbcp2.password}")
private String password;
public HibernateConfig() {
@PostConstruct
private void init(){
log.info("数据库配置初始化\ndburl="+url+",dbcp2.username="+username+",dbcp2.password="+password);
dataSource = new BasicDataSource();
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setUrl(url);
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
sessionFactoryBean = new LocalSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource);
this.setDataSource(dataSource);
Properties properties = new Properties();
properties.setProperty("hibernate.connection.pool_size", "5");
properties.setProperty("hibernate.jdbc.fetch_size", "50");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL57Dialect");
sessionFactoryBean.setHibernateProperties(properties);
sessionFactoryBean.setPackagesToScan("org.pqh.model");
try {
sessionFactoryBean.afterPropertiesSet();
} catch (IOException e) {
e.printStackTrace();
}
this.setHibernateProperties(properties);
this.setPackagesToScan("org.pqh.model");
}
@Bean("transactionManager")
public HibernateTransactionManager hibernateTransactionManager() {
HibernateTransactionManager hibernateTransactionManager = new HibernateTransactionManager();
hibernateTransactionManager.setSessionFactory(this.sessionFactoryBean.getObject());
hibernateTransactionManager.setSessionFactory(this.getObject());
return hibernateTransactionManager;
}
@Bean(name = "hibernateTemplate")
public HibernateTemplate hibernateTemplate() {
HibernateTemplate hibernateTemplate = new HibernateTemplate();
hibernateTemplate.setSessionFactory(sessionFactoryBean.getObject());
hibernateTemplate.setSessionFactory(this.getObject());
return hibernateTemplate;
}

@ -1,6 +1,5 @@
package org.pqh.achieve.config;
import org.pqh.core.annotation.EnableWebCrawlerConfiguration;
import org.pqh.core.config.HibernateConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
@ -14,7 +13,8 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableWebMvc
@EnableAspectJAutoProxy
@Import({HibernateConfig.class,WebCrawlerConfig.class})
@ComponentScan("org.pqh.achieve")
@Import({HibernateConfig.class})
public class SpringConfig extends WebMvcConfigurationSupport{
private static ApplicationContext applicationContext;

Loading…
Cancel
Save