1

我无法使用

PropertySourcesPlaceholderConfigurer

下面是我的代码..

应用程序上下文.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变量为空。因此无法获得该属性。我的问题是为什么它会为空。

4

0 回答 0