How to exclude a class from scanning with CDI 1.0
Asked Answered
U

4

10

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 .

Untenable answered 14/3, 2014 at 13:6 Comment(0)
P
10

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.

Prominence answered 14/3, 2014 at 18:14 Comment(1)
You referenced the version 1.1.16 of weld. Can I use the same configuration with weld 1.0.xx ?Untenable
M
2

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.

Matthei answered 14/3, 2014 at 15:6 Comment(0)
P
2

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.

Plantaineater answered 5/11, 2015 at 21:13 Comment(0)
B
0

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)

Blaspheme answered 1/6, 2016 at 6:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.