public interface PropertyFileConfig
If you implement this interface, the property files with the given file name will be registered as
ConfigSource
s.
There are 2 ways to register a PropertyFileConfig
ProcessAnnotatedType
phase
DeltaSpike will automatically pick up all the implementations which are
inside a Bean Archive (a JAR or ClassPath entry with a META-INF/beans.xml file) during the
ProcessAnnotatedType
phase and create a new instance via reflection. Thus the
implementations will need a non-private default constructor. There is no CDI injection being performed in
those instances! The scope of the implementations will also be ignored as they will not get picked up as CDI
beans.
Please note that the configuration will only be available after the boot is finished. This means that you cannot use this configuration inside a CDI Extension before the boot is finished!
Attention: When using this logic inside an EAR then you might get
different behaviour depending on the Java EE
server you are using. Some EE container use a different ClassLoader to bootstrap
the application than later to serve Requests.
In that case we would register the ConfigSources on the wrong ConfigResolver
(means we register it to the wrong ClassLoader). If you did hit such an application server
then you might need to switch back to manually register the
ConfigSource
or
ConfigSourceProvider
via the
ServiceLoader
mechanism described there.
java.util.ServiceLoader
mechanismIn case you have an EAR or you need the configured values already during the CDI container start
then you can also register the PropertyFileConfig via the java.util.ServiceLoader
mechanism.
To not have this configuration picked up twice it is required to annotate your own
PropertyFileConfig
implementation with Exclude
.
The ServiceLoader
mechanism requires to have a file
META-INF/services/org.apache.deltaspike.core.api.config.PropertyFileConfigcontaining the fully qualified Class name of your own
PropertyFileConfig
implementation class.
com.acme.my.own.SomeSpecialPropertyFileConfigThe implementation will look like the following:
@Exclude public class SomeSpecialPropertyFileConfig implements PropertyFileConfig { public String getPropertyFileName() { return "myconfig/specialconfig.properties" } public boolean isOptional() { return false; } }
Modifier and Type | Method and Description |
---|---|
String |
getPropertyFileName()
All the property files on the classpath which have this name will get picked up and registered as
ConfigSource s. |
boolean |
isOptional() |
String getPropertyFileName()
ConfigSource
s.boolean isOptional()
Copyright © 2016 The Apache Software Foundation. All rights reserved.