When I tried to load property file which is in the source code, I am getting issues. But when I tried to load property file externally, it working fine. Mentioned both working and not working code below. Can someone help me on this. I am a very new bee to Spring :)
The only change I did for loading property file from external and within the project is location declaration in context:property-placeholder.
Configured spring context to load property file from external as below. It worked very well.
When loaded property file from externally - working :
<context:property-placeholder location="file:///C:/Test/Data/WebDetails.properties"
ignore-resource-not-found="true" ignore-unresolvable="true" order="1" />
I configured my property file to load from project in a spring context as below - Not Working:
<bean id="webProperties" class="com.test.run.WebProperties" />
<context:property-placeholder location="file:./src/main/resources/WebDetails.properties"
ignore-resource-not-found="true" ignore-unresolvable="true" order="1" />
My WebDetails.properties is place in Maven Project under src/main/resources. And file looks like
url = www.testresponse.com
space = SampleSpace
And am mapping property values in WebProperties like below
@Component
public class WebProperties{
@Value("{url}") public String url;
@Value("{space}") public String space;
//getters
}
My Main class is :
public class ProcessWeb {
ApplicationContext context;
WebProperties webProperties;
}
public ProcessWeb () {
context = new ClassPathXmlApplicationContext("web-context.xml");
webProperties= (WebProperties) context.getBean("webProperties");
}
public void execute(String[] args){
webProperties.getURL()
}
public static void main(String args[])
{
ProcessWeb main = new ProcessWeb ();
main.execute();
}
When I executed my main class when load properties from code. I am getting error as ${url} (The system cannot find the file specified.)
How Should I configure My location path in placeholder?
More Info : Main class, ProcessWeb , will be called from a batch file. After deploying the code, when we executing that batch file from command prompt, am getting same issue for external properties as well. Is any configuration need to be change? We are packaging our code into jar files