1

を使用してプロパティを準備できません

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 になっています。したがって、プロパティを取得できません。私の質問は、なぜ null になるのかということです。

4

0 に答える 0