加载 Java 个配置文件的整个文件夹?
Load entire folder of Java Configuration files?
有没有什么方法可以用@Configuration 文件加载整个文件夹,就像 XML 有:<import resource="folder/*.xml" />
,但带有注释?
您或许可以使用组件扫描。
@Configuration
@ComponentScan(basePackages = "org.example.configs")
public class Config {
}
org.example.configs
包中的所有 @Configuration 类 都将包含在上下文中。
类型安全替代方案:
// org.example.configs.SubConfig
@ComponentScan(basePackageClasses = SubConfig.class)
<import resource="folder/*.xml" />
的挂件但是使用配置是@ImportResource
例如:
@Configuration
@ImportResource("folder/*.xml")
public class MyConfiguration {}
有没有什么方法可以用@Configuration 文件加载整个文件夹,就像 XML 有:<import resource="folder/*.xml" />
,但带有注释?
您或许可以使用组件扫描。
@Configuration
@ComponentScan(basePackages = "org.example.configs")
public class Config {
}
org.example.configs
包中的所有 @Configuration 类 都将包含在上下文中。
类型安全替代方案:
// org.example.configs.SubConfig
@ComponentScan(basePackageClasses = SubConfig.class)
<import resource="folder/*.xml" />
的挂件但是使用配置是@ImportResource
例如:
@Configuration
@ImportResource("folder/*.xml")
public class MyConfiguration {}