Unable to read properties using PropertySource

100 Views Asked by At

I am unable to ready the properties using

PropertySourcesPlaceholderConfigurer

Below is my code..

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>

Here is my property reader class

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");
           }
     }

The env variable is getting null. Hence unable to get the property .My question is why is it getting null.

0

There are 0 best solutions below