繁体   English   中英

spring有没有一种方法可以将属性文件注入到没有xml的bean中?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM