Search code examples
javawildflywildfly-10

Setting per application properties on Wildfly


I am normally the Tomcat guy but we use Widlfly on one of our client project.

With Tomcat, I can set "per application" properties by creating a separate context for each application, just as Tomcat documentation very nicely says.

This way, my WebApp1.war can run with my.property.value=Cat and WebApp2.war can run with my.property.value=Dog at the same time.

I haven't found any similar documentation / feature with Wildfly. Could you please advice me how to set properties to applications individually, or point me to the documentation?

Thank you. :-)


Solution

  • In Wildfly, you can create modules holding properties:

    • Under the ${JBOSS_HOME}/modules, add a directory like my/group/app1/conf/main.

    • Under the ${JBOSS_HOME}/modules/my/group/app1/conf/main, create the file module.xml with content:

      <?xml version="1.0" encoding="UTF-8"?>
      <module xmlns="urn:jboss:module:1.1" name="my.group.app1.conf">
              <resources>
                      <resource-root path="." />
                      <!-- Insert resources here -->
              </resources>
      </module>
      
    • Copy your *.properties file(s) under the ${JBOSS_HOME}/modules/my/group/app1/conf/main

    • Add as dependency <module name="my.group.app1.conf" export="true" /> in the jboss-deployment-structure.xml of the WebApp1.war

    • In a Spring XML, assuming you have in the configuration module a file named my-app.properties the properties can be loaded into the context with:

      <context:property-placeholder
              location="classpath*:*my-app.properties"
              local-override="false"
              ignore-unresolvable="false"/>
      

    To have a configuration module for the WebApp2.war, just repeat the steps above but the new module must have its own unique name.