I would like to exclude a class from scanning in CDI 1.0. I'm using the default implementation of CDI in WebLogic 12.1.12 (Weld, CDI 1.0).
I saw several web sites and docs with CDI 1.1 but not with the previous release .
With Weld, you can use a custom XML namespace in beans.xml
to exclude classes from scanning:
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:weld="http://jboss.org/schema/weld/beans">
<weld:scan>
<weld:exclude name="com.acme.swing.**"/>
</weld:scan>
</beans>
See the Weld Manual for details.
I once had this problem and failed to find a standard solution in CDI 1.0.
There's a workaround though: mark a bean with @Alternative
and don't select this alternative in beans.xml (that is don't list it in <alternatives>
element). It should do the trick.
Also in CDI 1.1 they filled this gap with scan/exclude element.
If @Vetoed
(available since CDI 1.1) would work for you, you can use @Typed()
without values or with Apache DeltaSpike @Exclude
.
If you can't(/don't like to)change the class, you can create a CDI-Extension and observer ProcessAnnotatedType
-> call #veto if e.g. processAnnotatedType.getAnnotatedType().getJavaClass()
returns the class you would like to exclude.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With