|
|
@ -1,20 +1,16 @@ |
|
|
|
package web.config; |
|
|
|
package web.config; |
|
|
|
|
|
|
|
|
|
|
|
import db.config.HibernateConfig; |
|
|
|
import db.config.HibernateConfig; |
|
|
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
|
|
|
|
|
|
|
import org.springframework.context.annotation.ComponentScan; |
|
|
|
import org.springframework.context.annotation.ComponentScan; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.PropertySource; |
|
|
|
import org.springframework.context.annotation.PropertySource; |
|
|
|
import org.springframework.http.converter.HttpMessageConverter; |
|
|
|
import org.springframework.http.converter.HttpMessageConverter; |
|
|
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; |
|
|
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; |
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|
|
|
import org.springframework.orm.hibernate5.HibernateTemplate; |
|
|
|
|
|
|
|
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor; |
|
|
|
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor; |
|
|
|
import org.springframework.web.servlet.config.annotation.*; |
|
|
|
import org.springframework.web.servlet.config.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by reborn on 2017/7/28. |
|
|
|
* Created by reborn on 2017/7/28. |
|
|
@ -25,8 +21,6 @@ import java.util.Map; |
|
|
|
@ComponentScan({"web.controller","web.service","web.util"}) |
|
|
|
@ComponentScan({"web.controller","web.service","web.util"}) |
|
|
|
|
|
|
|
|
|
|
|
public class SpringConfig implements WebMvcConfigurer { |
|
|
|
public class SpringConfig implements WebMvcConfigurer { |
|
|
|
@Resource |
|
|
|
|
|
|
|
private DefaultListableBeanFactory beanFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void configureViewResolvers(ViewResolverRegistry registry) { |
|
|
|
public void configureViewResolvers(ViewResolverRegistry registry) { |
|
|
@ -42,13 +36,11 @@ public class SpringConfig implements WebMvcConfigurer { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void addInterceptors(InterceptorRegistry registry) { |
|
|
|
public void addInterceptors(InterceptorRegistry registry) { |
|
|
|
Map<String, HibernateTemplate> hibernateTemplateMap= HibernateConfig.get(); |
|
|
|
HibernateConfig.get().forEach((key,hibernateTemplate)->{ |
|
|
|
for(String key:hibernateTemplateMap.keySet()) { |
|
|
|
|
|
|
|
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor(); |
|
|
|
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor(); |
|
|
|
interceptor.setSessionFactory(hibernateTemplateMap.get(key).getSessionFactory()); |
|
|
|
interceptor.setSessionFactory(hibernateTemplate.getSessionFactory()); |
|
|
|
registry.addWebRequestInterceptor(interceptor); |
|
|
|
registry.addWebRequestInterceptor(interceptor); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|