WildFly Swarm: Example for MicroProfile Config (OpenShift)

Parent POM for JBoss projects. Provides default project build configuration.

License

License

Categories

Categories

WildFly Container Application Servers config Application Layer Libs Configuration OpenShift PaaS Providers
GroupId

GroupId

org.wildfly.swarm
ArtifactId

ArtifactId

microprofile-config-openshift-example
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

war
Description

Description

WildFly Swarm: Example for MicroProfile Config (OpenShift)
Parent POM for JBoss projects. Provides default project build configuration.
Project Organization

Project Organization

JBoss by Red Hat

Download microprofile-config-openshift-example

How to add to project

<!-- https://jarcasting.com/artifacts/org.wildfly.swarm/microprofile-config-openshift-example/ -->
<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>microprofile-config-openshift-example</artifactId>
    <version>1.2.1</version>
    <type>war</type>
</dependency>
// https://jarcasting.com/artifacts/org.wildfly.swarm/microprofile-config-openshift-example/
implementation 'org.wildfly.swarm:microprofile-config-openshift-example:1.2.1'
// https://jarcasting.com/artifacts/org.wildfly.swarm/microprofile-config-openshift-example/
implementation ("org.wildfly.swarm:microprofile-config-openshift-example:1.2.1")
'org.wildfly.swarm:microprofile-config-openshift-example:war:1.2.1'
<dependency org="org.wildfly.swarm" name="microprofile-config-openshift-example" rev="1.2.1">
  <artifact name="microprofile-config-openshift-example" type="war" />
</dependency>
@Grapes(
@Grab(group='org.wildfly.swarm', module='microprofile-config-openshift-example', version='1.2.1')
)
libraryDependencies += "org.wildfly.swarm" % "microprofile-config-openshift-example" % "1.2.1"
[org.wildfly.swarm/microprofile-config-openshift-example "1.2.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.wildfly.swarm : jaxrs jar
org.wildfly.swarm : microprofile-config jar 1.2.1

provided (1)

Group / Artifact Type Version
javax : javaee-api jar 7.0

Project Modules

There are no modules declared in this project.

wildfly-microprofile-config

WildFly/Thorntail Extension for Eclipse MicroProfile Config, based on the SmallRye Config implementation.

Build Status

Instructions

mvn clean install

Project structure

  • extension - WildFly Extension that provides the microprofile-config subsystem. It also allows to define ConfigSources that are stored in the subsystem configuration.
  • feature-pack - Feature pack that bundles the extension with the JBoss Modules required to run it in WildFly and Thorntail.
  • dist - A distribution of WildFly with the microprofile-config extension installed (in its standalone-microprofile.xml configuration)
  • config-api - Generation of Thorntail Config API that provides a Java API to manage the microprofile-config subsystem.

Example

Once this project has been installed, go to the examples/simple directory to run the simple example.

The Web endpoint is using the Eclipse MicroProfile Config to read the value of the some properties:

@Inject
Config config;

@Inject
@ConfigProperty(name = "BAR", defaultValue = "my BAR property comes from the code")
String bar;

@Inject
@ConfigProperty(name = "BOOL_PROP", defaultValue = "no")
boolean boolProp;

...
Optional<String> foo = config.getOptionalValue("FOO", String.class);
...

The Eclipse MicroProfile Config can be used by the application by adding the corresponding Thorntail fractions:

<dependency>
  <groupId>io.thorntail</groupId>
  <artifactId>microprofile-config</artifactId>
  <version>${project.version}</version>
</dependency>

First, run the simple example:

$ cd examples/simple/
$ mvn thorntail:run
...
2017-04-14 10:35:24,416 WARN  [org.wildfly.swarm] (main) WFSWARM0013: Installed fraction: Eclipse MicroProfile Config - UNSTABLE        io.thorntail:microprofile-config:1.0-SNAPSHOT
...
2017-04-14 10:35:30,676 INFO  [org.wildfly.swarm] (main) WFSWARM99999: Thorntail is Ready

If you go to http://localhost:8080/hello, you will see the message:

$ curl http://localhost:8080/hello
FOO property = Optional[My FOO property comes from the microprofile-config.properties file]
BAR property = my BAR property comes from the code
BOOL_PROP property = false

The application has configured its FOO property in its microprofile-config.properties file. The BAR and BOOL_PROP properties are configured with defaultValue using the @ConfigProperty annotation.

Let's now restart the application with the FOO, BAR, and BOOL_PROP environment variables set:

$ BOOL_PROP="yes" FOO="my FOO property comes from the env" BAR="my BAR property comes from the env" mvn wildfly-swarm:run
...
2017-04-14 10:35:30,676 INFO  [org.wildfly.swarm] (main) WFSWARM99999: WildFly Swarm is Ready

If you now go again to http://localhost:8080/hello, you will see the message:

$ curl http://localhost:8080/hello
FOO property = Optional[my FOO property comes from the env]
BAR property = my BAR property comes from the env
BOOL_PROP property = true

Links

org.wildfly.swarm

WildFly extras

Community extras for WildFly

Versions

Version
1.2.1
1.2.0
1.1.5
1.1.4
1.1.2
1.1.1
1.1.0
1.0.1
1.0.0