Deploy two springboot applications in Wildfly with external properties

Uncategorized

Deploy two springboot applications in Wildfly with external properties

Posted By Mariusz Wyszomierski

Personally I prefer jar then war (“Make JAR, not WAR” – Josh Long), but sometimes we have constraints that are not depend on us.
This example focus about how to deploy two springboot applications in Wildfly and how to externalize application properties for each application.

The case is:

  • deploy two springboot applications in Wildfly,
  • each application has its own properties,
  • properties need to be loaded from external source (not from jar)
There is also alternative solution for example use of Spring Cloud Config, but it requires additional server.

Let’s assume that we have two microservices:
Service1 with properties:

  • speedlog.common-name-property
  • service1.specific

Service2 with properties:

  • speedlog.common-name-property
  • service2.specific

Because we have two application that has property with the same name (speedlog.common-name-property) we can’t set this property in:

  • environment variable
  • system properties
  • JVM args of Wildfly

If we do so, both applications would have the same value of this property.
So let’s check how we can externalize properties for both applications.

We will add to each application actuator library to easy check properties value in runtime.
We also need to expose “env” endpoint in properties.
So in each application resources we have something like this:

service1/src/main/resources/application.properties
management.endpoints.web.exposure.include=env

# some properties
speedlog.common-name-property="this should be overwritten after deploy"
service1.specific="this should be overwritten after deploy"
service2/src/main/resources/application.properties
management.endpoints.web.exposure.include=env

# some properties
speedlog.common-name-property="this should be overwritten after deploy"
service2.specific="this should be overwritten after deploy"

Now let’s imagine that we need to override preferences from application resources, when we deploy it in Wildfly.

Example solution may be a JBoss/Wildfly module with application properties file.

Below instructions for “service1”. For “service2” it will be analogous:
1) We need to add some files in application sources.


service1/scr/main/webapp/WEB-INF/jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="pl.speedlog.example.twoappinwildfly.service1.configuration"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

In this file we declare where JBoss/Wildfly should find configuration of our module.

And optional we can add in the same directory (WEB-INF) file “jboss-web.xml” to declare root context (URL) of application.

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
      http://www.jboss.com/xml/ns/javaee
      http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
    <context-root>service1</context-root>
</jboss-web>

2) Now we add a module to Wildfly.
In Wildfly “module” directory add directory tree that we declare in “jboss-deployment-structure.xml”.
So we should create directory “pl/speedlog/example/twoappinwildfly/service1/configuration” and then additional “main” directory.

3) Add module definition and properties file for application.
In directory that we create in previous point, we create file “module.xml”.
The “name” of module should be the same as in “jboss-deployment-structure.xml” in source code of application.

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="pl.speedlog.example.twoappinwildfly.service1.configuration">
    <resources>
        <resource-root path="."/>
    </resources>
</module>

And now we can create “application.properties” for our application.

management.endpoints.web.exposure.include=env

# override properties
speedlog.common-name-property="This is text from jboss module of service 1"
service1.specific="Service 1 specific"

Warning:
If you place here application.properties file it will override properties file from application resources!

Just want to override only few properties? There is a simple solution.
a) create file with override properties with profile name for example: application-uat.properties.
b) add to your system environment variable to run application in “uat” profile:
SPRING_PROFILES_ACTIVE=uat
Now application should load application properties from “application.properties” in application resources and “application-uat.properties” from JBoss/Wildfly module.

4) Now just deloy app in Wildfly and you can check value of properties by link:
http://localhost:8080/service1/actuator/env/speedlog.common-name-property
http://localhost:8080/service1/actuator/env/service1.specific

Described example with two deployed application is on github:
https://github.com/speedlog/two-app-in-wildfly

Declaration of JBoss/Wildfly module is here:
https://github.com/speedlog/two-app-in-wildfly/tree/master/docker/wildfly/pl/speedlog/example/twoappinwildfly/service1/configuration/main

Read More

Uncategorized

Turn off “X-Powered-By” i “Server” headers in WildFly 10

Posted By Mariusz Wyszomierski

According to OWASP recommendations “Fingerprint Web Application Framework (OTG-INFO-008)” you must turn off specific headers, which are sent by application server or used framework. The less informations attacker knows, the harder it will be to attack.

Below are instructions to run in jboss-cli in standalone mode.

$WILDFLY_HOME/bin/jboss-cli.sh --connect

(more…)

Read More

Tools

Mapping Dozer vs MapStruct

Posted By Mariusz Wyszomierski

In multi-tier applications there is often a need for mapping between two data models. In this article you can read about comparing two mapping libraries:

(more…)

Read More

Raspberry Pi

How to safety turn off Raspberry Pi?

Posted By Mariusz Wyszomierski

RaspberryPi card doesn’t have no default turn off button.
You can’t just disconnect it from power supply – it may cause problems with SD card.
Firstly you should execute command:

sudo shutdown -h now
Read More

Tools

Generator .gitignore file

Posted By Mariusz Wyszomierski

What is .gitignore file?

It’s a file containing names or pattern names of directories and files, that should’t be included in GIT repository.
These are among others files generated by IDE – in case of IntelliJ IDEA it’s a directory .idea and file with extension *.iml. (more…)

Read More

Raspberry Pi

How to set static IP address in Raspbian?

Posted By Mariusz Wyszomierski

Option 1 – set static IP address in router

Many routers have settings to assign static IP address based on MAC addres of network card.
Each router has different administration panel, so I won’t describe this option in detail.
If IP address of your local network is 192.168.0.15 you probably can access in browser “http://192.168.0.1/” to administration panel of router. (more…)

Read More

Raspberry Pi

How to check address IP of newly connected Raspberry Pi?

Posted By Mariusz Wyszomierski

In this post i will show you how to check IP address of your raspberry after you connect it to network. (more…)

Read More

Raspberry Pi

How to install OS on Raspberry Pi without keyboard and screen?

Posted By Mariusz Wyszomierski

What is needed?

  1. 8GB microSD recommended
  2. Raspberry Pi device
  3. Network cable for router connection

(more…)

Read More