Friday 15 January 2010

tomcat - External configuration for spring-boot application -


I have a spring-boot application that I want to run with an external configuration file. When I run it jar (with embedded servlet container), then all is fine. But I want to run it under the external servlet container (Tomcat) and here I have a problem with the external configuration I have tried a @PropertySource, but in this case only the battle file configuration has the missing properties: external configuration internal If the configuration does not override, then question: How do I configure external configurations that allow internal configuration Can override?

You are probably using the current directory when you are running your application as a jar External configuration in the form of application.properties . However, while deploying a war in outer tokkets, the "current directory" is not very useful, even if you know what is the current directory, then the highest place for all apps running in that tome So, when you run more than one app, it does not work very well.

What we do here, it declares two property sources on our application:

  @PropertySources ({@SourceSource (value = {"Classpath: internal.properties"}), @PropertySource (value = {"file: $ {application.properties}"})})  

internal.properties includes the "built-in" default value propeties. Second, property resources is a file with an external configuration, note that the name of the file itself is the name of the property.

We define this in the context of our code (in the code) in the context element:

   & Lt; / Context & gt;  

This allows you to run many applications in Tomcat, each application is a file of its own external properties. You are running same You can also get many examples of applications.


No comments:

Post a Comment