spring利用注解@Value获取properties属性为null, 求解~

手写白 手写白 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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;
}
...全文

相关推荐

评论 40
收藏 已收藏
分享
返回顶部
手写白
Java EE 67,535 成员 225,843 内容