-
Notifications
You must be signed in to change notification settings - Fork 2
Using @Property
Apply the org.soulwing.cdi.properties.@Property
qualifier along with @Inject
on fields, methods, constructors, and producer parameters wherever you want a property value injected.
By default, the fully-qualified name of the annotated member is the name of the corresponding property value that will resolved (as described below) and injected. For example:
package org.example;
import javax.inject.Inject;
import org.soulwing.cdi.properties.Property;
public class MyBean {
@Inject @Property
private URL location;
@Inject @Property(name = "uniqueIdentifier", value = "42")
private long identifier;
}
The @Property
annotations on this bean will instruct the extension to resolve a property named org.example.MyBean.location
and inject it into the location
field. It will also resolve a property named uniqueIdentifier
(note that the name
attribute overrides the default property name) and inject it into the identifier
field. If the uniqueIdentifier
property cannot be resolved, the value 42 will be used by default. Since the location
property does not have a default value, CDI bean resolution will fail if the corresponding property cannot be resolved.
Using the built-in capabilities of the extension, you can inject values into the bean shown in the above example by creating a META-INF/beans.properties
file:
org.example.MyBean.location=http://www.google.com
uniqueIdentifier=42
To learn more about how property values are resolved, read the section on Property Resolution. To learn more about supported types for property injection and how to provide converters for your own value types, read Supported Types.