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