Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a class from scanning with CDI 1.0

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 .

like image 887
Alexandre T Avatar asked Mar 14 '14 13:03

Alexandre T


3 Answers

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.

like image 155
Harald Wellmann Avatar answered Nov 03 '22 02:11

Harald Wellmann


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.

like image 2
Yuri Avatar answered Nov 03 '22 03:11

Yuri


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.

like image 2
Dar Whi Avatar answered Nov 03 '22 03:11

Dar Whi