spring利用注解@Value获取properties属性为null, 求解~
properties文件路径没有错,tomcat启动正常,可是就是显示wingPath为null,这是为什么??第一次发帖,各路大神过来看下~

data.properties:
mallPath = store/mall.json
wingPath = wing/wing.json
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!-- ====================== 将多个配置文件读取到容器中,交给Spring管理 ===================== -->
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>/WEB-INF/classes/data.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties"></property>
</bean>java:
import org.springframework.beans.factory.annotation.Value;
public class IndexInitAction {
@Value("#{configProperties['wingPath']}")
private String wingPath; // 这里就是得不到值,!
public String getWingPath() {
return wingPath;
}
public void setWingPath(String wingPath) {
this.wingPath = wingPath;
}
...全文
相关推荐
java类文件通过$获取properties文件的属性值
java类文件通过$获取properties文件的属性值
Springboot中@Value的使用详解
主要介绍了Springboot中@Value的使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
SpringBoot读取配置文件常用方法解析
主要介绍了SpringBoot读取配置文件常用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
SpringBoot的拦截器中依赖注入为null的解决方法
主要介绍了SpringBoot的拦截器中依赖注入为null的解决方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
JAVA读取properties文件的值
JAVA读取properties的值,JAVA读取properties文件,JAVA读取properties的内容


