如何仅在Spring中通过注释配置组件扫描? [英] How to configure component-scan by annotation only in Spring?

查看:117
本文介绍了如何仅在Spring中通过注释配置组件扫描?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在tomcat webserver环境中运行war文件。

I'm running a war file on a tomcat webserver environment.

我有一个基于注释的配置 @Beans ,和webservices的xml配置:

I have an annotation based config for @Beans, and a xml config for webservices:

@Configuration
//@ComponentScan(basePackageClasses = ...)
public class AppConfig {
    //beans @Bean
}

applicationContext.xml:

applicationContext.xml:

<beans>
    <context:component-scan base-package="..."/>
    <jaxws:endpoint ... />
</bean>

问题:我想定义 @ComponentScan 通过注释只有类型安全。但如果我这样做,则不会执行扫描。相反,当我使用< context:component-scan .. 时,一切正常。

Problem: I would like to define @ComponentScan by annotation only to have typesafety. But if I do so, the scanning is not performed. In contrast, when I use <context:component-scan.. everything works fine.

Spring 组件扫描是否与用于软件包扫描的xml配置相关联?

Is Spring component scanning within a webserver tied to configuration with xml for the package scanning?

推荐答案

浏览 http:// docs .spring.io / spring-javaconfig / docs / 1.0.0.M4 / reference / html / ch06s02.html
类似的东西。

Go through http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch06s02.html Something Like.

    @Configuration
    @ComponentScan("com.company") // search the com.company package for @Component classes
    @ImportXml("classpath:com/company/data-access-config.xml")        
    public class Config {
    }

这篇关于如何仅在Spring中通过注释配置组件扫描?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆