`@Autowire`正在工作,即使<context:annotation-config>没有Annotation替换,

时间:2017-02-10 09:26:39

标签: java spring

我有一个使用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;
    }

}

1 个答案:

答案 0 :(得分:0)

这似乎是您正在寻找的link

@Configuration
@AnnotationDrivenConfig
public class Config {
    // may now use @Autowired to reference beans from other @Configuration classes, XML, etc
}