0

I created a config.properties file located in: WEB_INF folder. On my local its working well but after I'm upload the war to remote and trying to get some property I get exception,

This is the way that I get some property in code:

@PropertySource(value = { "WEB-INF/config.properties" })
@Autowired 
Environment environment; 
String databasehost=this.environment.getProperty("DB_HOST");

can someone explain me what is wrong? I already tried to check if this file exist inside the war that uploaded, and it was... thank you!

user6319790
  • 55
  • 1
  • 11
  • what exception you are getting ? – Deepak Sharma Jun 16 '16 at 07:43
  • Different environment causes reading/writing file problem is usually because the reading/writing operation of that file/folder is not open to the container you use, ie. tomcat. – Tiina Jun 16 '16 at 07:49
  • Have you checked the file is actually in the archive? Are you sure the file is in the classpath? The classpath in your IDE may be different from the one on the application server. – Wesley De Keirsmaeker Jun 16 '16 at 07:59
  • @ Tiina so what can I do to resolve this problem? – user6319790 Jun 16 '16 at 08:02
  • @Wesley De Keirsmaeker how can I check it? I see the file in WEB_INF but not in classes folder is it good? – user6319790 Jun 16 '16 at 08:03
  • Not sure what you you are using... `@PropertySource` on a field doesn't work, only a class. What exception do you get?... Currently your information is incomplete and inconsistent.. – M. Deinum Jun 16 '16 at 08:06
  • 1
    We always place these configuration files in the classes folder. [link](http://stackoverflow.com/questions/793917/is-web-inf-in-the-classpath) This post says WEB_INF isn't on the classpath. – Wesley De Keirsmaeker Jun 16 '16 at 08:10
  • 1
    WEB-INF is not in the classpath. Try to move your properties to src/main/resources (or any other source folder) and then use @PropertySource("classpath:config.properties") – Marco A. Hernandez Jun 16 '16 at 08:14
  • Ok thank you I'm trying your answer now, if it's will be good I will tell you. – user6319790 Jun 16 '16 at 08:27
  • The exception is:"Could not get JDBC Connection;" – user6319790 Jun 16 '16 at 08:41
  • I'm trying to get DB name, HostName, password from this file but the server cant access to this DB, when I'm writing it by hard code its working fine. what is wrong? – user6319790 Jun 16 '16 at 08:42
  • Its look like the server get the properties from this file, but still can't access to the DB someone have any idea about it? – user6319790 Jun 16 '16 at 08:54

0 Answers0