'How to load an external property file to Spring Boot in Wildfly

I wonder how can I load an external property of my application running inside Wildfly 9 as WAR, I tried to add a java parameter to Wildfly execution but it seems the application did not recognize the properties.

-Dspring.config.location=file:///C:\Temp\config\application.properties,classpath:application.properties

Is there any way how Spring Boot could read the external property file? I am trying to load and run one Spring Boot application as WAR inside Wildfly.

I'd appreciate any help.

Thanks.



Solution 1:[1]

If your springboot application is running inside Wildfly you don't need to read standalone.xml as an external file.

Get the property value directly with System.getProperty(PROPERTY_NAME);

Solution 2:[2]

I know it's a bit late for the answer, but maybe this helps:

  • Within your deployment-descriptor (web.xml), create environment-variables pointing to the spring config location file, i.e.

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
               version="3.0">
          <env-entry>
              <env-entry-name>spring.config.location</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>file:[path-to-file]/[your-properties-file] 
    </env-entry-value>
          </env-entry>
      </web-app>
    

Working on Wildfly 25.0.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rogerio A. Valente
Solution 2