"@Autowire"正在工作,即使没有注释替换<上下文:注释配置/>,



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

我用相应的注释替换了以下 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;
    }
}

这似乎是您要查找的链接

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

最新更新