@PropertySource配合@ConfigurationProperties获取配置文件的元素
@PropertySource(value ={"classpath:person.properties"} )
@ConfigurationProperties(prefix = "person")
@ImportResource
在启动类中导入配置文件(Spring的自定义配置文件等)
@ImportResource(value = {"classpath:beans.xml"})
@Configration 配置类
@Bean 装备bean
@Configuration
public class AppConfig {
@Bean
public HelloService helloService(){
return new HelloService();
}
}
本文介绍如何使用@PropertySource和@ConfigurationProperties注解来加载Spring配置文件,并展示了如何通过@ImportResource导入自定义配置文件,以及如何在启动类中进行配置。此外还提供了@Configuration类和@Bean方法的具体应用实例。
2711

被折叠的 条评论
为什么被折叠?



