You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
webcrawler/web/src/main/java/web/config/SpringConfig.java

37 lines
1.3 KiB

package web.config;
import core.config.HibernateConfig;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Created by reborn on 2017/7/28.
*/
@EnableWebMvc
@PropertySource("classpath:config.properties")
@ComponentScan({"${spring.scan}"})
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class SpringConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/jsp/",".jsp");
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
OpenSessionInViewInterceptor interceptor=new OpenSessionInViewInterceptor();
interceptor.setSessionFactory(HibernateConfig.sessionFactoryBean.getObject());
registry.addWebRequestInterceptor(interceptor);
}
}