AppConfig.java
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = {xxx}, excludeFilters = @Filter(Controller.class))
public class AppConfig {
}
WebMvcConfig.java
@Configuration
@ComponentScan(basePackages = {xxx})
public class WebMvcConfig extends WebMvcConfigurationSupport {
MybatisConfig.java
@Configuration
@PropertySource("classpath:jdbc.properties")
@MapperScan("xxx")
@ImportResource("classpath:transaction.xml")
public class MybatisConfig {
}
MyWebAppInitializer.java
public class MyWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{AppConfig.class, MybatisConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{WebMvcConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
SpringMVC全注解配置时,定制Jackson配置,不生效。原因是我开启@EnableWebMvc 然后又继承了WebMvcConfigurationSupport。查看@EnableWebMvc,发现其注解解析的类为DelegatingWebMvcConfiguration而其又是继承WebMvcConfigurationSupport。