我使用的是Spring,并且我有一长串的子包,我需要在<context:component-scan>标签中逐个指定它们吗?
<context:component-scan base-package="com.fooapp.mainpackage,
com.fooapp.mainpackage.subpackage1,
com.fooapp.mainpackage.subpackage2,
com.fooapp.mainpackage.subpackage3" />发布于 2011-07-24 22:18:29
组件扫描支持包层次结构,因此这应该是可行的:
<context:component-scan base-package="com.fooapp.mainpackage"/>这很容易而且更快地验证你自己--你试过了吗?
发布于 2011-07-25 03:02:41
此外,我想补充的是,默认情况下,使用@Component、@Repository、@Service、@Controller注释的类,或者本身使用@Component注释的自定义注释是唯一检测到的候选组件。
您可以通过应用include-filter或exclude-filter自定义过滤器来更改此行为
例如:
<context:component-scan base-package="com.vanilla">
<context:exclude-filter
type="annotation"
expression="org.springframework.stereotype.Repository"/>
</context:component-scan>它将排除所有@Repository注释。
https://stackoverflow.com/questions/6807230
复制相似问题