Search code examples
javajakarta-eecdideltaspike

Excluding a CDI Bean based on a PropertyFileConfig (DeltaSpike, WebSphere 8.5.5)


I am trying to exclude a Bean implementation using the DeltaSpike 1.0 @Exclude-Annotation. The exclusion should be based on a property value like this:

@Exclude(onExpression = "providerimplementation!=mock")

I created a PropertyFileConfig returning my .properties file name to let DeltaSpike pick up the configured value and used this @Exclude in two different implementing beans, each of them being excluded like above.

The configuration is included in an EAR as a .jar file and both implementations sit in different .jar files inside the EAR.

I am trying to deploy the whole archive onto a WebSphere 8.5.5 Server and on startup I get a javax.enterprise.inject.AmbiguousResolutionException for the injection point.

It seems to me that the PropertyFileConfig is not picked up before the expression resolution, although I found references to this kind of pattern (http://deltaspike.apache.org/core.html#exclude and https://groups.google.com/forum/#!topic/java-config/xsleMKST3rU), so I wonder what's wrong with my setup.


Solution

  • First answer :

    Unfortunately, properties defined via the PropertyFileConfig facility can't be used with @Exclude.

    That's because the extension ConfigurationExtension only registers PropertyFileConfig at the end of the container initialization (which is problably mandatory as PropertyFileConfig classes are used as CDI Beans)

    Instead you have to use the default ConfigSource implementations : http://deltaspike.apache.org/documentation/configuration.html#_configsources_provided_by_default or create your own custom ConfigSource

    In particular a quick workaround here, is to defined your property in the default property file : META-INF/apache-deltaspike.properties instead of a custom property file

    Edit :

    In fact my previous answer is incomplete (at least with the last version of DeltaSpike (1.3.0 today)) : the javadoc for PropertyFileConfig now documents this limitation AND shows another way to configure custom property files using the serviceloader facility : http://deltaspike.apache.org/javadoc/1.3.0/org/apache/deltaspike/core/api/config/PropertyFileConfig.html