3

I wanted to set application.properties file outside of the war file while deploying on the tomcat and here is my observation

1. When i was setting jvm property as

spring.config.location=C:/Users/user_name/Documents/Softwares/apache-tomcat-8.0.53-windows-x64/apache-tomcat-8.0.53/webapps/config/ 

in the catalina.properties file.. it was not understood by the tomcat and threw runtime error in reading one location property that is defined in the application.properties file (basically it couldn't resolve the location)

but when i set the profile as below

spring.profiles.active=dev

and the profile was picked up correctly.

so, what is the big difference in setting these two properties. also i believe these are these are jvm properties that spring boot take as environment properties in runtime. am i correct here?

2. when i set the same spring.config.location in a new file named setenv.sh as below

set JAVA_OPTS=-Dspring.config.location=C:/Users/user_name/Documents/Softwares/apache-tomcat-8.0.53-windows-x64/apache-tomcat-8.0.53/webapps/config/

meanind setting the property as the java system variable, this time spring boot application picked it up correctly.

so, what is the big difference in setting a property through catalina.properties file than to setenv.bat file.

Kindly enlighten.

Reese
  • 389
  • 2
  • 10
  • 26

1 Answers1

1
  1. A properties file is not a text file. It has its own syntax. See Javadoc of class java.util.Properties [1][2] for a reference.

    E.g. ':' is escaped as ':', '\' is escaped as '\'.

    (Escaping ':' is important in the key of a property. I am not sure that it is required in the value. Maybe you have some other errors in your value.)

    You can configure org.apache.catalina.startup.VersionLoggerListener (in server.xml) to log the actual values of System properties, as seen by Tomcat and by your web applications. The attribute is logProps="true" [3].

  2. setenv.sh or setenv.bat script generates options for the command line of java program.

    The catalina.properties file is processed by Tomcat bootstrap process. It happens rather early (before Tomcat classloader hierarchy is built), but for some properties this timing difference is important.

    For example, the properties that configure java.util.logging Logging API should be configured in setenv.sh and not in the catalina.properties file.

Konstantin Kolinko
  • 3,854
  • 1
  • 13
  • 21