Announcement Announcement Module
Collapse
No announcement yet.
Param in property file confusion Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Param in property file confusion

    I have config file

    <bean id="propertyPlaceholderConfigurer"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:db.properties</value>
    </list>
    </property>
    </bean>

    <bean id="loadConfig" class="Spring.LoadConfigFileTest">
    <property name="user" value="${ssss}"/>
    </bean>
    </beans>

    My db.properties looks like

    user=TR
    pwd=TR

    I have included a property from a file which is not present in .proeprty file. When i load the config file and refer to that property "user", its not throwing any errors. It prints the vale us "${ssss}".

    public class LoadConfigFileTest{

    private String user;

    public String getUser() {
    return user;
    }

    public void setUser(String user) {
    this.user = user;
    }

    public static void main(String[] args)
    {
    Resource resource = new FileSystemResource("./spring-config.xml");
    BeanFactory beanFactory = new XmlBeanFactory(resource);
    LoadConfigFileTest loadConfig = (LoadConfigFileTest)beanFactory.getBean("loadConfi g");
    System.out.println("Loaded---"+loadConfig.getUser());
    }
    }

    Ideally i should get an exception that the property being referred is not present. So what wrong?

  • #2
    References to nonexistent properties do not result in exceptions.

    You might consider using the "@Required" annotation on the instance variable or setter. Perhaps that will work. Alternatively, you could define a @PostConstruct method to verify your settings.

    Comment


    • #3
      Thanks. Even if i refer to existing property from file, its not picking the value it shows {user}. Why its happening?

      Comment


      • #4
        Elaborate. Show details.

        Comment

        Working...
        X