2013-07-10 73 views
1

我有一個只能有選擇地動態加載的類,當有其他依賴項可用時。CDI:從掃描中排除類的註釋

但CDI(焊接)掃描它並報告一個醜陋的錯誤,見下文。

如何擺脫它,理想情況下使用一些註釋?

Registered contexts: [interface javax.enterprise.context.RequestScoped, interface javax.enterprise.context.ApplicationScoped, interface javax.enterprise.context.ConversationScoped, interface javax.enterprise.context.Dependent, interface javax.enterprise.context.SessionScoped, interface javax.inject.Singleton] 
Registered beans: 0 
: [<class>org.jboss.weld.environment.se.jpa.JpaTransactionInterceptor</class> in jar:file:/home/ondra/.m2/repository/org/jboss/jawabot/JawaBot-core/2.0.0.GA-SNAPSHOT/JawaBot-core-2.0.0.GA-SNAPSHOT.jar!/META-INF/[email protected]] 
10:45:12.713 INFO [main] org.jboss.weld.ClassLoading WELD-000119 Not generating any bean definitions from org.jboss.jawabot.plugin.jira.tools.ProjectsListDownloader because of underlying class loading error 
10:45:12.714 INFO [main] org.jboss.weld.ClassLoading catching 
org.jboss.weld.resources.spi.ResourceLoadingException: java.lang.NoClassDefFoundError: org/codehaus/jettison/json/JSONException 
    at org.jboss.weld.environment.se.discovery.url.WeldSEResourceLoader.classForName(WeldSEResourceLoader.java:61) 
    at org.jboss.weld.bootstrap.BeanDeployer.loadClass(BeanDeployer.java:107) 
    at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:77) 
    at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:135) 
    at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:184) 
    at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:349) 
    at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.deployBeans(ForwardingBootstrap.java:70) 
    at org.jboss.weld.environment.se.Weld.initialize(Weld.java:133) 
    at org.jboss.jawabot.JawaBotApp.main(JawaBotApp.java:74) 
Caused by: java.lang.NoClassDefFoundError: org/codehaus/jettison/json/JSONException 
    at java.lang.Class.getDeclaredMethods0(Native Method) 
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2451) 
    at java.lang.Class.getDeclaredMethods(Class.java:1810) 
    at org.jboss.weld.environment.se.discovery.url.WeldSEResourceLoader.classForName(WeldSEResourceLoader.java:54) 
    ... 8 more 
Caused by: java.lang.ClassNotFoundException: org.codehaus.jettison.json.JSONException 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
    ... 12 more 
10:45:12.931 WARN [main] org.jboss.weld.interceptor.util.InterceptionTypeRegistry Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled 
10:45:12.931 WARN [main] org.jboss.weld.interceptor.util.InterceptionTypeRegistry Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled 
10:45:12.955 DEBUG [main] org.jboss.weld.Bootstrap WELD-000108 Decorator: Decorator [class org.jboss.weld.environment.se.threading.RunnableDecorator] decorates [Runnable] with delegate type [Runnable] and delegate qualifiers [@Default] 
10:45:12.956 DEBUG [main] org.jboss.weld.Bootstrap WELD-000107 Interceptor: Interceptor [class org.jboss.weld.environment.se.jpa.JpaTransactionInterceptor intercepts @JpaTransactional] 

回答

2

沒有註釋做開箱即用,但是Apache Deltaspike和其他幾個人提供@Veto

不是添加依賴你可能只是做一個簡單的CDI擴展,將否決你的類型,像這樣:

public class VetoExtension implements Extension { 

    public void vetoMyType(@Observes ProcessAnnotatedType<YourTypeGoesHere> pat) { 
     pat.veto(); 
    } 

} 

你可以看到這個更多的進入和一個具體的例子:CDI Portable Extensions

根據@ LightGuard的以下評論,在CDI 1.1中,這將與@Vetoed

+0

開箱即用。右,我看着@Vetoed,但我的應用程序沒有與Weld 2.x一起工作,也許我會看看進入它,修復並使用它。 –