-
Jan 4th, 2012, 06:41 AM
#1
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?
-
Jan 4th, 2012, 10:49 AM
#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.
-
Jan 4th, 2012, 11:45 PM
#3
Thanks. Even if i refer to existing property from file, its not picking the value
it shows {user}. Why its happening?
-
Jan 5th, 2012, 12:01 AM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules