Spring not able to find classpath resource with @PropertySource
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
Rama Arjun
Updated on November 01, 2020Comments
-
Rama Arjun over 3 years
I am using
@PropertySource
in my datasource configuration file to get property files located on classpath. Below is my project structure.I believe I can do it in two ways:
- By creating a package in
src
folder and add them there. Assrc
folder is already included in the classpath in eclipse, following should work.
@PropertySources({ @PropertySource("classpath: com/spring/property/general.properties"), @PropertySource("classpath: com/spring/property/hibernate.properties") })
- Second way is to create a
resources
folder and add it to the classpath and following should work
@PropertySources({ @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.
EDIT: I have changed my project structure to include properties file in
src/java/resources
and I can see theresources
folder in build path. Still.properties
are not found by spring. - By creating a package in
-
Rushino over 5 yearsit is the same with a non-maven project?