关于@Value(“${xxx}”)取不到值的原因,首先保证spring-mvc.xml里面的配置正确
<bean id="configProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:view.properties</value>
<value>classpath:configfilename.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
以及applicationContent.xml的配置正确,以及web.xml的正确配置....................
在保证以上的配置的正确性之后,在加上
<context:property-placeholder location="classpath:配置文件的地址" ignore-unresolvable="true"/>
该配置,则可以获取到正确配置文件.properties文件的值
本文详细解析了在Spring MVC中如何正确配置属性文件,确保@Value注解能够成功读取.properties文件中的值。从spring-mvc.xml和applicationContent.xml的配置出发,到web.xml的设置,最后通过<context:property-placeholder>标签完成配置文件的加载,确保应用程序能够顺利读取外部配置。
594

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



