//1,在spring的配置文件中,注入properties文件
spring-config.xml
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:resource/system.properties</value>
</list>
</property>
</bean>
//2,可以直接通过注解获取system.properties文件中key=HTTP_IMG_PATH的value值
@Value("#{configProperties['HTTP_IMG_PATH']}") //spring注入Bean(configProperties),直接获取value
private String httpImgPath;
Spring_通过注入获取配置文件的值
最新推荐文章于 2025-07-25 12:24:41 发布
本文介绍如何在Spring配置文件中注入properties文件,并通过注解直接获取其中的属性值。示例展示了使用spring-config.xml配置properties文件路径,以及如何利用@Value注解读取特定属性。

1万+

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



