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 .
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.
I had the same problem, and as @Yuri said, You can achieve it using the @Alternative annotation if You can modify the class, but if You can't (e.g. it is a third party library), then You can't control it.
If You check the xsd of cd 1.0 (http://java.sun.com/xml/ns/javaee/beans_1_0.xsd), You won't find a tag, which could help You.
BTW there is WebLogic 12.1.1 and there is 12.1.2, but there is no WebLogic 12.1.12. (https://en.wikipedia.org/wiki/Oracle_WebLogic_Server#Application_Server_versions)
© 2022 - 2024 — McMap. All rights reserved.