blob: c9cfe3e9b91372392041062017d58285bb2cf845 [file] [log] [blame]
:jbake-type: page
:jbake-status: published
= Apache Tamaya - Extension: Microprofile Implementation
toc::[]
[[Spring]]
== Tamaya Microprofile Implementation (Extension Module)
Tamaya _Microprofile_ is an extension module. Refer to the link:../extensions.html[extensions documentation] for further details.
=== What functionality this module provides ?
Tamaya _Microprofile_ currently provides full integration for the Microprofile Configuration API:
* A Microprofile +ConfigSource+ implementation can be used with Tamaya.
* A Tamaya +PropertySource+ can be used with any Microprofile implementation.
* The same is also true for +Converter,PropertyConverter+.
* Nevertheless Tamaya also fully implements the Microprofile API and also successfully is compatible with the
Microprofile TCK.
=== Compatibility
Both modules are based on Java 8. The implemented Microprofile API is currently
version 1.1.
=== Installation
To benefit from Tamaya Microprofile you only must one of the following dependencies to your module:
[source, xml]
-----------------------------------------------
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-microprofile</artifactId>
<version>{tamaya_version}</version>
</dependency>
-----------------------------------------------
=== Using Microprofile API
Refer to http://microprofile.io/project/eclipse/microprofile-config for details on how the API works and should be used. In general, you will see
many similarities with Tamaya, since Tamaya heavily influenced the design of microprofile.io regarding configuration.
Nevertheless Tamaya's API is much more complete and provides far more feature as of now. Further changes in this area
may be good to be expected, since as of now also a corresponding specification (JSR) has been started and will
be supported by Tamaya as well.
[source, java]
--------------------------------------------------------
// SE API
Config config = Configuration.current();
String serverUrl = config.getValue("acme.myprj.some.url", String.class);
callToServer(serverUrl);
// =====================================================================
// CDI Injection API
@ApplicationScoped
public class InjectedConfigUsageSample {
@Inject
private Config config;
//The property myprj.some.url must exist in one of the configsources, otherwise a
//DeploymentException will be thrown.
@Inject
@ConfigProperty(name="myprj.some.url")
private String someUrl;
//The following code injects an Optional value of myprj.some.port property.
//Contrary to natively injecting the configured value this will not lead to a
//DeploymentException if the configured value is missing.
@Inject
@ConfigProperty(name="myprj.some.port")
private Optional<Integer> somePort;
//Injects a Provider for the value of myprj.some.dynamic.timeout property to
//resolve the property dynamically. Each invocation to Provider#get() will
//resolve the latest value from underlying Config.
//The existence of configured values will get checked during startup.
//Instances of Provider<T> are guaranteed to be Serializable.
@Inject
@ConfigProperty(name="myprj.some.dynamic.timeout", defaultValue="100")
private javax.inject.Provider<Long> timeout;
}
--------------------------------------------------------