我无法使用
准备好属性PropertySourcesPlaceholderConfigurer
以下是我的代码..
的applicationContext.xml
<beans
xmlns:context="http://www.springframework.org/schema/context"
xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd" >
<context:component-scan base-package="com.medapp" />
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="location" value="classpath:gui.properties"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
这是我的属性读者类
MedAppPropertyReader
package com.medapp.propertyreader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
public class MedAppPropertyReader {
@Autowired private Environment env;
public String getProperty(String keyName) {
System.out.println("Env "+env);-->Its printing null here
return env.getProperty("somekey");
}
}
env 变量变为null。因此无法获得财产 我的问题是为什么它会变空。