blob: 9c33165a145229c6816d792ac8fa550cdc28ba15 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<title>ConfigProperty</title>
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
<link rel="shortcut icon" href="/img/microprofile-favicon.png">
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="ConfigProperty";
}
}
catch(err) {
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/eclipse/microprofile/config/inject/ConfigProperties.Literal.html" title="class in org.eclipse.microprofile.config.inject"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/eclipse/microprofile/config/inject/ConfigProperty.html" target="_top">Frames</a></li>
<li><a href="ConfigProperty.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#annotation.type.field.summary">Field</a>&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#annotation.type.field.detail">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.eclipse.microprofile.config.inject</div>
<h2 title="Annotation Type ConfigProperty" class="title">Annotation Type ConfigProperty</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>@Retention(value=RUNTIME)
@Target(value={METHOD,FIELD,PARAMETER,TYPE})
public @interface <span class="memberNameLabel">ConfigProperty</span></pre>
<div class="block">Binds the injection point with a configured value.
<p>
Can be used to annotate injection points of type <code>TYPE</code>, <code>Optional&lt;TYPE&gt;</code> or
<code>javax.inject.Provider&lt;TYPE&gt;</code>, where <code>TYPE</code> can be <code>String</code> and all types which have appropriate
converters.
<p>
Injected values are the same values that would be retrieved from an injected
<a href="../../../../../org/eclipse/microprofile/config/Config.html" title="interface in org.eclipse.microprofile.config"><code>Config</code></a> instance or from the instance retrieved from
<a href="../../../../../org/eclipse/microprofile/config/ConfigProvider.html#getConfig--"><code>ConfigProvider.getConfig()</code></a>
<h2>Examples</h2>
<h3>Injecting Native Values</h3>
<p>
The first sample injects the configured value of the <code>my.long.property</code> property. The injected value does not
change even if the underline property value changes in the <a href="../../../../../org/eclipse/microprofile/config/Config.html" title="interface in org.eclipse.microprofile.config"><code>Config</code></a>.
<p>
Injecting a native value is recommended for a mandatory property and its value does not change at runtime or used by
a bean with RequestScoped.
<p>
A further recommendation is to use the built in <code>META-INF/microprofile-config.properties</code> file mechanism to
provide default values inside an Application. If no configured value exists for this property, a
<code>DeploymentException</code> will be thrown during startup.
<pre>
&#064;Inject
&#064;ConfigProperty(name = "my.long.property")
private Long injectedLongValue;
</pre>
<h3>Injecting Optional Values</h3>
<p>
Contrary to natively injecting, if the property is not specified, this will not lead to a DeploymentException. The
following code injects a Long value to the <code>my.optional.long.property</code>. If the property is not defined, the
value <code>123</code> will be assigned to <code>injectedLongValue</code>.
<pre>
&#064;Inject
&#064;ConfigProperty(name = "my.optional.long.property", defaultValue = "123")
private Long injectedLongValue;
</pre>
<p>
The following code injects an Optional value of <code>my.optional.int.property</code>.
<pre>
&#064;Inject
&#064;ConfigProperty(name = "my.optional.int.property")
private Optional&lt;Integer&gt; intConfigValue;
</pre>
<h3>Injecting Dynamic Values</h3>
<p>
The next sample injects a Provider for the value of <code>my.long.property</code> property to resolve the property
dynamically. Each invocation to <code>Provider#get()</code> will resolve the latest value from underlying
<a href="../../../../../org/eclipse/microprofile/config/Config.html" title="interface in org.eclipse.microprofile.config"><code>Config</code></a> again. The existence of configured values will get checked during
startup. Instances of <code>Provider&lt;T&gt;</code> are guaranteed to be Serializable.
<pre>
&#064;Inject
&#064;ConfigProperty(name = "my.long.property" defaultValue="123")
private Provider&lt;Long&gt; longConfigValue;
</pre>
<p>
If <code>ConfigProperty</code> is used with a type where no <a href="../../../../../org/eclipse/microprofile/config/spi/Converter.html" title="interface in org.eclipse.microprofile.config.spi"><code>Converter</code></a> exists,
a deployment error will be thrown.</div>
<dl>
<dt><span class="simpleTagLabel">Examples (en):</span></dt>
<dd><a href="../../../../../../../../tomee-9.0/examples/mp-config-source-database.html">mp-config-source-database</a>, <a href="../../../../../../../../tomee-9.0/examples/mp-config-example.html">mp-config-example</a></dd>
<dt><span class="simpleTagLabel">Examples (es):</span></dt>
<dd><a href="../../../../../../../../tomee-9.0/es/examples/mp-config-source-database.html">mp-config-source-database</a>, <a href="../../../../../../../../tomee-9.0/es/examples/mp-config-example.html">mp-config-example</a></dd>
<dt><span class="simpleTagLabel">Examples (pt):</span></dt>
<dd><a href="../../../../../../../../tomee-9.0/pt/examples/mp-config-source-database.html">mp-config-source-database</a>, <a href="../../../../../../../../tomee-9.0/pt/examples/mp-config-example.html">mp-config-example</a></dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== ANNOTATION TYPE FIELD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.field.summary">
<!-- -->
</a>
<h3>Field Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation">
<caption><span>Fields</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Fields and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/eclipse/microprofile/config/inject/ConfigProperty.html#UNCONFIGURED_VALUE">UNCONFIGURED_VALUE</a></span></code>&nbsp;</td>
</tr>
</table>
</li>
</ul>
<!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.optional.element.summary">
<!-- -->
</a>
<h3>Optional Element Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation">
<caption><span>Optional Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Optional Element and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/eclipse/microprofile/config/inject/ConfigProperty.html#defaultValue--">defaultValue</a></span></code>
<div class="block">The default value if the configured property does not exist.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/eclipse/microprofile/config/inject/ConfigProperty.html#name--">name</a></span></code>
<div class="block">The key of the config property used to look up the configuration value.</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ ANNOTATION TYPE FIELD DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.field.detail">
<!-- -->
</a>
<h3>Field Detail</h3>
<a name="UNCONFIGURED_VALUE">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>UNCONFIGURED_VALUE</h4>
<pre>public static final&nbsp;java.lang.String&nbsp;UNCONFIGURED_VALUE</pre>
</li>
</ul>
</li>
</ul>
<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.element.detail">
<!-- -->
</a>
<h3>Element Detail</h3>
<a name="name--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>name</h4>
<pre>public abstract&nbsp;java.lang.String&nbsp;name</pre>
<div class="block">The key of the config property used to look up the configuration value.
<p>
If it is not specified, it will be derived automatically as <code>&lt;class_name&gt;.&lt;injection_point_name&gt;</code>, where
<code>injection_point_name</code> is the field name or parameter name, <code>class_name</code> is the fully qualified name
of the class being injected to.
<p>
If one of the <code>class_name</code> or <code>injection_point_name</code> cannot be determined, the value has to be
provided.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>Name (key) of the config property to inject</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>""</dd>
</dl>
</li>
</ul>
</li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="defaultValue--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>defaultValue</h4>
<pre>public abstract&nbsp;java.lang.String&nbsp;defaultValue</pre>
<div class="block">The default value if the configured property does not exist. This value acts as a configure source with the
lowest ordinal.
<p>
If the target Type is not String, a proper <a href="../../../../../org/eclipse/microprofile/config/spi/Converter.html" title="interface in org.eclipse.microprofile.config.spi"><code>Converter</code></a> will get
applied.
Empty string as the default value will be ignored, which is same as not setting the default value. That means
that any default value string should follow the formatting rules of the registered Converters.
If a property has been emptied by a config source with a higher ordinal by setting an empty configuration value
or by using a value causing the used converter returning <code>null</code>, the default value will not be used.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the default value as a string</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>"org.eclipse.microprofile.config.configproperty.unconfigureddvalue"</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/eclipse/microprofile/config/inject/ConfigProperties.Literal.html" title="class in org.eclipse.microprofile.config.inject"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/eclipse/microprofile/config/inject/ConfigProperty.html" target="_top">Frames</a></li>
<li><a href="ConfigProperty.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#annotation.type.field.summary">Field</a>&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#annotation.type.field.detail">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>