Rama Arjun Rama Arjun - 1 year ago 161
Java Question

Spring not able to find classpath resource with @PropertySource

I am using

in my datasource configuration file to get property files located on classpath. Below is my project structure.

enter image description here

I believe I can do it in two ways:

  1. By creating a package in
    folder and add them there. As
    folder is already included in the classpath in eclipse, following should work.

@PropertySource("classpath: com/spring/property/general.properties"),
@PropertySource("classpath: com/spring/property/hibernate.properties")

  1. Second way is to create a
    folder and add it to the classpath and following should work

@PropertySource("classpath: general.properties"),
@PropertySource("classpath: hibernate.properties")

In my case neither of the two is working. Being an intermediate java developer this still confuses me. Can anybody guide me in the right direction. And also how we can configure classpath resources for Spring in a production environment.

I have changed my project structure to include properties file in
and I can see the
folder in build path. Still
are not found by spring.

enter image description here

Answer Source

For anybody facing problem with usign .properties files in Spring 4+, look at the thread below to match your setup with that of OP. Setup is all good except for a whitespace in configuration.

Not able to inject .properties file into Spring MVC 4.3 using @PropertySource

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download