如何使用@ComponentScan注释扫描多路径? [英] How to scan multiple paths using the @ComponentScan annotation?

查看:1436
本文介绍了如何使用@ComponentScan注释扫描多路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Spring 3.1和自举使用 @Configuration @ComponentScan 属性的应用程序。

I'm using Spring 3.1 and bootstrapping an application using the @Configuration and @ComponentScan attributes.

实际开始与完成

new AnnotationConfigApplicationContext(MyRootConfigurationClass.class);

此配置类都被注解

@Configuration
@ComponentScan("com.my.package")
public class MyRootConfigurationClass

和这工作得很好。不过,我想具体谈谈我扫描,所以我尝试了包。

and this works fine. However I'd like to be more specific about the packages I scan so I tried.

@Configuration
@ComponentScan("com.my.package.first,com.my.package.second")
public class MyRootConfigurationClass

然而,这失败的错误,告诉我​​它无法找到使用 @Component 标注指定的组件。

什么是做什么,我经过了正确的方法是什么?

What is the correct way to do what I'm after?

感谢

推荐答案

<一个href=\"http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/context/annotation/ComponentScan.html\">@ComponentScan使用字符串数组,像这样的:

@ComponentScan uses string array, like this:

@ComponentScan({"com.my.package.first","com.my.package.second"})

当你只在一个字符串提供多个包名,春间$ P $点这是一个软件包名称,因此无法找到它。

When you provide multiple package names in only one string, Spring interprets this as one package name, and thus can't find it.

这篇关于如何使用@ComponentScan注释扫描多路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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