我有一个使用config xml文件开发的项目,我们必须更改它基于注释的配置 -
<!--To Scan stereo type bean such as (@Component,@Controller,etc)-->
<context:component-scan base-package="com.ttnd.springdemo.*" />
<!--To Activete web related annotaion such as (@RequestMapping,@ModelAttribute etc)-->
<mvc:annotation-driven />
<!--To Register All Bean Post Processor which activate respective annotaion those are registered in container by @ComponentScan such as AutowiredAnnotationBeanPostProcessor for @Autowire -->
<context:annotation-config />
我用相应的Annotation替换了下面的xml元素 -
<context:component-scan>
的 @ComponantScan
<mvc:annotation-driven />
@EnableWebMvc
但是<context:annotation-config />
没有使用任何替代品,即使@Autowire
正在运作!
从AutowiredAnnotationBeanPostProcessor
即将到来的地方!
以下是我的配置类 -
@Configuration
@ComponentScan(basePackages = {"com.ttnd.mvc_mod.controller","com.ttnd.mvc_mod.services"})
@EnableWebMvc
public class MvcConfig {
@Bean
public ViewResolver getViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}
答案 0 :(得分:0)
这似乎是您正在寻找的link
@Configuration
@AnnotationDrivenConfig
public class Config {
// may now use @Autowired to reference beans from other @Configuration classes, XML, etc
}