【发布时间】:2011-07-05 18:23:24
【问题描述】:
我为 spring 上下文使用注释配置,例如
<context:annotation-config/>
<context:component-scan base-package="example"/>
但项目相当大,扫描两个组件需要很多时间(一次扫描 10 秒)。 我可以只在一次扫描中配置它吗?
【问题讨论】:
标签: java spring configuration annotations
我为 spring 上下文使用注释配置,例如
<context:annotation-config/>
<context:component-scan base-package="example"/>
但项目相当大,扫描两个组件需要很多时间(一次扫描 10 秒)。 我可以只在一次扫描中配置它吗?
【问题讨论】:
标签: java spring configuration annotations
我认为base-package 值实际上可以包含多个包。尝试指定如下内容:
<context:component-scan base-package="example.package.one,example.package.two"/>
您明确指定只需要的包。
【讨论】:
10s 根本不是很多时间,因为它只执行一次 - 在启动时。您可以通过指定更详细的包名称(不仅仅是example)来限制扫描的包。
您提到“两者” - 如果您只有 2 个 spring bean,只需在 XML 中使用 <bean> 列出它们并删除组件扫描。
【讨论】: