Set Spring Boot external properties file using JBoss/Wildfly run config.

Answered

I have a Spring Boot application. It does not use an embedded servlet. It runs via WildFly.

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
servletContext.setInitParameter("server.error.whitelabel.enabled", "false");
servletContext.setInitParameter("spring.config.location", "file:/custom/conf/my-config.properties");

super.onStartup(servletContext);
}

That is where the default/production file is set for UNIX environments. This needs overridden for dev environments, on Windows. In the JBoss run config, we set "-Dspring.config.location=file:c:\path\to\my.properties" in the VM Options field. App fails to start as my @Value annotations cannot find the properties. Spring Boot does not output any messages regarding an inability to find this file or the one set via the above snippet. I have no idea if it is even loading either of them.

I see that if I were to use a Spring Boot run config, I can override the properties file name. This does not help, as I need a new location.

I see that if I were to use a Spring Boot run config, I can add additional properties files - however, it refuses to let me navigate outside of the project directory. This is in no way helpful.

Even if those worked for me, I cannot use Spring Boot run config, because this needs to go through Wildfly - again, no embedded servlet is even available to the application. `spring-boot-starter-tomcat` is excluded from the `spring-boot-starter-web` dependency.

 

In previous spring (non-boot) applications I simply used a 1-liner in the XML to set where the file was and could overwrite it by using a -D parameter in the VM Options. It was so easy.

How can I set this property? What am I doing wrong? Why is this so difficult?

0
2 comments

Apparently, `setInitParameter()` will override anything given in the command line. I commented it out and everything worked. I guess we can't hard-code a default for 99% of our use cases. Oh, well :|

0

Derek,

You are welcome to create feature request for such cases on YouTrack: http://youtrack.jetbrains.com/issues/IDEA.

0

Please sign in to leave a comment.