修改配置类

master
luffy9412 7 years ago
parent 2ee63efef7
commit 299451516f
  1. 5
      core/pom.xml
  2. 25
      core/src/main/java/org/pqh/core/config/HibernateConfig.java
  3. 8
      pom.xml
  4. 27
      web/src/main/java/org/pqh/achieve/config/SpringConfig.java
  5. 10
      web/src/main/java/org/pqh/config/AbstractWebConfig.java
  6. 25
      web/src/main/java/org/pqh/config/SpringConfig.java
  7. 2
      web/src/main/java/org/pqh/config/WebConfigImpl.java
  8. 2
      web/src/main/java/org/pqh/config/WebCrawlerConfig.java
  9. 2
      web/src/main/java/org/pqh/controller/AdminController.java
  10. 2
      web/src/main/java/org/pqh/controller/BaseController.java
  11. 2
      web/src/main/java/org/pqh/controller/ConfigController.java
  12. 2
      web/src/main/java/org/pqh/controller/ParamController.java
  13. 10
      web/src/main/resources/config.properties

@ -84,6 +84,11 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>core</finalName> <finalName>core</finalName>

@ -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();
} }

@ -27,6 +27,7 @@
<commons-io.version>RELEASE</commons-io.version> <commons-io.version>RELEASE</commons-io.version>
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<servlet-api.version>3.1.0</servlet-api.version> <servlet-api.version>3.1.0</servlet-api.version>
<druid.version>1.1.3</druid.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -116,6 +117,13 @@
<version>${junit.version}</version> <version>${junit.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

@ -1,27 +0,0 @@
package org.pqh.achieve.config;
import org.pqh.core.config.HibernateConfig;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
/**
* Created by reborn on 2017/7/28.
*/
@Configuration
@EnableWebMvc
@EnableAspectJAutoProxy
@ComponentScan("org.pqh.achieve")
@Import({HibernateConfig.class})
public class SpringConfig{
@Bean("viewReslover")
public InternalResourceViewResolver internalResourceViewResolver(){
InternalResourceViewResolver internalResourceViewResolver=new InternalResourceViewResolver();
internalResourceViewResolver.setPrefix("/WEB-INF/jsp/");
internalResourceViewResolver.setSuffix(".jsp");
return internalResourceViewResolver;
}
}

@ -1,13 +1,11 @@
package org.pqh.achieve.config; package org.pqh.config;
import com.alibaba.druid.support.http.StatViewServlet;
import org.pqh.core.util.LogManger; import org.pqh.core.util.LogManger;
import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import javax.servlet.DispatcherType; import javax.servlet.*;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.EnumSet; import java.util.EnumSet;
/** /**
@ -40,6 +38,8 @@ public class AbstractWebConfig extends AbstractAnnotationConfigDispatcherServlet
FilterRegistration.Dynamic dynamic=super.registerServletFilter(servletContext,new CharacterEncodingFilter(encoding)); FilterRegistration.Dynamic dynamic=super.registerServletFilter(servletContext,new CharacterEncodingFilter(encoding));
dynamic.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*"); dynamic.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
ServletRegistration.Dynamic servlet=servletContext.addServlet("DruidStatView", StatViewServlet.class);
servlet.addMapping("/druid/*");
} }
} }

@ -0,0 +1,25 @@
package org.pqh.config;
import org.pqh.core.config.HibernateConfig;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* Created by reborn on 2017/7/28.
*/
@Configuration
@EnableWebMvc
@EnableAspectJAutoProxy
@PropertySource("classpath:config.properties")
@ComponentScan({"${spring.scan:org.pqh.controller}"})
@Import({HibernateConfig.class,WebCrawlerConfig.class})
public class SpringConfig extends WebMvcConfigurerAdapter{
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/jsp/",".jsp");
}
}

@ -1,4 +1,4 @@
package org.pqh.achieve.config; package org.pqh.config;
import org.pqh.core.util.LogManger; import org.pqh.core.util.LogManger;
import org.springframework.web.WebApplicationInitializer; import org.springframework.web.WebApplicationInitializer;

@ -1,4 +1,4 @@
package org.pqh.achieve.config; package org.pqh.config;
import org.pqh.core.annotation.EnableWebCrawlerConfiguration; import org.pqh.core.annotation.EnableWebCrawlerConfiguration;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

@ -1,4 +1,4 @@
package org.pqh.achieve.controller; package org.pqh.controller;
import org.pqh.core.util.LogManger; import org.pqh.core.util.LogManger;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

@ -1,4 +1,4 @@
package org.pqh.achieve.controller; package org.pqh.controller;
import org.pqh.core.model.AbstractModel; import org.pqh.core.model.AbstractModel;
import org.pqh.core.service.BaseService; import org.pqh.core.service.BaseService;

@ -1,4 +1,4 @@
package org.pqh.achieve.controller; package org.pqh.controller;
import org.pqh.core.model.Config; import org.pqh.core.model.Config;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

@ -1,4 +1,4 @@
package org.pqh.achieve.controller; package org.pqh.controller;
import org.pqh.core.model.Param; import org.pqh.core.model.Param;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

@ -1,7 +1,11 @@
hibernate.connection.pool_size=5 #-----------------------hibernateÅäÖÃ-----------------------------
hibernate.jdbc.fetch_size=50
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true hibernate.connection.url=jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true
hibernate.connection.username=root hibernate.connection.username=root
hibernate.connection.password=0d4h0a3a hibernate.connection.password=
#-----------------------DruidDataSourceÅäÖÃ-----------------------
druid.maxActive=20

Loading…
Cancel
Save