在 spring 中的多个 beans 配置文件上使用“<import resource=”?
Using '<import resource=' on multiple beans profiles in spring?
在我的应用程序中-context.xml,我正在使用
<import resource="classpath*:com/companyName/projectName/dao/dao-beans.xml"/>
在dao-beans.xml文件中,我使用的是
<beans profile="profile1;profile2;profile">
<import resource="classpath*:com/companyName/projectName/dao/spring/xyz/xyz-dao-beans.xml" />
</beans>
我很困惑这部分是什么意思 -
<beans profile="profile1;profile2;profile">
这是否意味着对于要导入的 xyz-dao-beans.xml 中的所有 bean,所有 3 个配置文件都应该处于活动状态,或者即使这 3 个配置文件中的任何一个处于活动状态,也将导入 xyz dao bean?
可以参考this documentation:
This is analogous to the behavior in Spring XML: if the profile attribute of the beans element is supplied e.g., <beans profile="p1,p2">, the beans element will not be parsed unless at least profile 'p1' or 'p2' has been activated. Likewise, if a @Component or @Configuration class is marked with @Profile({"p1", "p2"}), that class will not be registered or processed unless at least profile 'p1' or 'p2' has been activated.
在我的应用程序中-context.xml,我正在使用
<import resource="classpath*:com/companyName/projectName/dao/dao-beans.xml"/>
在dao-beans.xml文件中,我使用的是
<beans profile="profile1;profile2;profile">
<import resource="classpath*:com/companyName/projectName/dao/spring/xyz/xyz-dao-beans.xml" />
</beans>
我很困惑这部分是什么意思 -
<beans profile="profile1;profile2;profile">
这是否意味着对于要导入的 xyz-dao-beans.xml 中的所有 bean,所有 3 个配置文件都应该处于活动状态,或者即使这 3 个配置文件中的任何一个处于活动状态,也将导入 xyz dao bean?
可以参考this documentation:
This is analogous to the behavior in Spring XML: if the profile attribute of the beans element is supplied e.g., <beans profile="p1,p2">, the beans element will not be parsed unless at least profile 'p1' or 'p2' has been activated. Likewise, if a @Component or @Configuration class is marked with @Profile({"p1", "p2"}), that class will not be registered or processed unless at least profile 'p1' or 'p2' has been activated.