Not able to load properties from file system using spring
Kamal Bindra
Greenhorn
Joined: May 18, 2012
Posts: 8
posted
0
Hi,
I am facing an issue regarding not able to load properties from file system defined on my local.
I am able to successfully connect to MySQL db using hibernate and spring but the problem is that i have to make db properties configurable means getting db properties from application.properties file on my file system rather than the one in classes folder in class path. i hope i am able to provide enough info wt my problem is because i have just started to use this forum so don't exactly know how to
provide info..below is the context.XML file..please help me to fix the issue...
If the properties file is not on your classpath you should be getting a FileNotFoundException. If you are getting exceptions always be sure to post them with your question along with the full stack trace.
To access a file not on the classpath try this
of course it should be the path to where your properties are located.
Have you tried to set the 'resourceLoader' property for your ReloadableResourceBundleMessageSource? I think you should use a org.springframework.core.io.FileSystemResourceLoader and then change the 'basename' property to use the file protocol.
In summary:
replacing path/to with the absolute path of the properties file.
Kamal Bindra
Greenhorn
Joined: May 18, 2012
Posts: 8
posted
0
Thanks Bill for your quick reply.
I am not getting any exceptions. the only thing is if i delete driver from application.properties file on my file system even then it is able to get the required value for db driver as it is not using file system's application.properties file. so what i want is if i need to change anything in future it can be done through application.properties file in local file system rather has to be through application.properties file in application. and as per your suggestion i cant use absolute path as i want to use relative path.
Thanks James for your quick reply.
I haven't tried it what you have suggested but the path that i need to provide cannot be absolute path as what i want is if i need to change anything in future it can be done through application.properties file in local file system rather has to be through application.properties file in application.
Kamal Bindra wrote:Thanks Bill for your quick reply.
I am not getting any exceptions. the only thing is if i delete driver from application.properties file on my file system even then it is able to get the required value for db driver as it is not using file system's application.properties file.l
Sorry but that does not make sense. If it is not getting it from your properties file where would it come from? Do you have other PropertyPlaceholderConfigurers or properties files you are not telling us about? Perhaps a duplicate application.properties on the classpath somewhere? The value has to be loaded from somewhere.
While this might not be what is happening. But by default PropertyPlaceholderConfigurer doesn't just stop at the .properties file. It will then check System.getProperty() then the operating environment variables. Then after that if it can't find it it will throw an exception.