如何将Spring配置文件设置为包?
发布于 2021-01-29 20:34:42
我想将配置文件名称设置为整个程序包,但我不知道如何。如果在哪里不是简单的方法,那么我必须用@Profile
注释标记包和子包中的每个类。
<context:component-scan/>
标签不支持这样的属性,profile
所以我不知道。
关注者
0
被浏览
66
1 个回答
-
您可以将个人资料设置为:
Spring Beans XML
文件-用于xml配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" profile="your-profile"> <context:component-scan base-package="your.package" /> </beans>
@Configuration
Java配置类
@Configuration @Profile("your-profile") @Componentscan("your.package") class AppConfig { }
在它们的每一个中,您都可以对特定的软件包使用组件扫描。