项目作者: wildfly-extras

项目描述 :
WildFly/Swarm extension for Eclipse MicroProfile Config
高级语言: Java
项目地址: git://github.com/wildfly-extras/wildfly-microprofile-config.git
创建时间: 2017-05-10T09:51:40Z
项目社区:https://github.com/wildfly-extras/wildfly-microprofile-config

开源协议:Apache License 2.0

下载


wildfly-microprofile-config

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

Build Status/statusIcon)

Instructions

  1. 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:

  1. @Inject
  2. Config config;
  3. @Inject
  4. @ConfigProperty(name = "BAR", defaultValue = "my BAR property comes from the code")
  5. String bar;
  6. @Inject
  7. @ConfigProperty(name = "BOOL_PROP", defaultValue = "no")
  8. boolean boolProp;
  9. ...
  10. Optional<String> foo = config.getOptionalValue("FOO", String.class);
  11. ...

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

  1. <dependency>
  2. <groupId>io.thorntail</groupId>
  3. <artifactId>microprofile-config</artifactId>
  4. <version>${project.version}</version>
  5. </dependency>

First, run the simple example:

  1. $ cd examples/simple/
  2. $ mvn thorntail:run
  3. ...
  4. 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
  5. ...
  6. 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:

  1. $ curl http://localhost:8080/hello
  2. FOO property = Optional[My FOO property comes from the microprofile-config.properties file]
  3. BAR property = my BAR property comes from the code
  4. 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:

  1. $ BOOL_PROP="yes" FOO="my FOO property comes from the env" BAR="my BAR property comes from the env" mvn wildfly-swarm:run
  2. ...
  3. 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:

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

Links