我有一个只使用可选项的类,当有其他依赖项可用时,动态加载。
但是CDI(Weld)会扫描它并报告一个丑陋的错误,见下文。
如何摆脱它,理想情况下使用一些注释?
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/beans.xml@11]
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]
答案 0 :(得分: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