[英]Spring bean injection - inject properties after bean has been defined
[英]does spring has a way to inject properties file to bean without xml?
我正在编写一个当前使用spring的javaconfig而不包含spring xml文件的项目。 现在我面临一个问题。
我有一个属性配置文件,我想将其设置为spring的@Component
,但是我找不到像在@Configuration
使用@PropertySource
一样将属性注入bean字段的好方法。 它使用@Value
或@Inject
Environment获取属性。
现在我的bean不是@Configuration,并且我不想在@Configuration
类中使用@Bean
来实现。 我希望它在春天之前自动扫描。
有人有想法吗?
在Java配置中
@Configuration
@PropertySource(name = "props", value = { "classpath:myProps.properties" })
public class AppConfig {
在一些春豆
@Autowired
@Qualifier("props")
private Properties myProperties;//+setter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.