Reputation: 2004
I have created one client application which consumes restfull web service. It is MAVEN java project. I have defined all URL for web service in properties file. If I run this client separately it works fine and gives proper result. Now I have created jar of the same application and added in the build path of another web application. When i deploy web application it gives error FileNotFoundException
. It is unable to read property file in jar.
@Autowired
private Environment props;
public String getAllAccounts(){
try {
return restEasyClient.invokeService(props
.getProperty("GET_ALL_ACCOUNTS"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is a code that work as a separate java project but not as a jar in web application.
This is how I am reading properties file using spring:
<bean name="props" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/client.properties</value>
</list>
</property>
</bean>
Any help??
Upvotes: 1
Views: 1532
Reputation: 198
You are using a / after classpath: I think that the problem is because you are not reaching properly the location of your File, consider this documentation http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-classpath-wildcards Also consider that classpath will look by itself inside of src/main/resources, src/test/resources, src/main/java and src/test/java.
Upvotes: 3