How to exclude a class from scanning using CDI 1.0

I would like to exclude a class from scanning in CDI 1.0. I am using the standard CDI implementation in WebLogic 12.1.12 (Weld, CDI 1.0).

I have seen several websites and documents with CDI 1.1, but not with the previous version.

+6
source share
4 answers

With Weld, you can use your own 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 Welding Guide for more information.

+5
source

I once had this problem and could not find a standard solution in CDI 1.0.
There is a workaround: mark the bean with @Alternative and do not select this alternative in beans.xml (that is, do not specify it in the <alternatives> element). That should do the trick.
Also in CDI 1.1 they filled this gap with the scan / exclude element.

+1
source

If @Vetoed (available with CDI 1.1) will work for you, you can use @Typed () with no values ​​or with Apache DeltaSpike @Exclude. If you cannot (/ dislike) changing the class, you can create a CDI extension and an observer ProcessAnnotatedType -> call #veto if, for example, processAnnotatedType.getAnnotatedType (). getJavaClass () returns the class you would like to exclude.

+1
source

I had the same problem, and as @Yuri said, you can achieve this using the @Alternative annotation, if you can change the class, but if you cannot (like this is a third-party library) then you can't control it .

If you check xsd cd 1.0 ( http://java.sun.com/xml/ns/javaee/beans_1_0.xsd ), you will not find a tag that can help you.

By the way, there is WebLogic 12.1.1 and 12.1.2, but no WebLogic 12.1.12. ( https://en.wikipedia.org/wiki/Oracle_WebLogic_Server#Application_Server_versions )

0
source

All Articles