Exception using weld CDI with Jetty: Singleton not set for STATIC_INSTANCE

跟風遠走 提交于 2020-12-08 06:20:32

问题


I am trying to configure Jetty with JSF and Weld CDI. After following this manual, I stumble upon the following stacktrace:

Caused by: java.lang.IllegalStateException: Singleton not set for STATIC_INSTANCE => []
    at org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider$RegistrySingleton.get(RegistrySingletonProvider.java:28)
    at org.jboss.weld.Container.instance(Container.java:55)
    at org.jboss.weld.SimpleCDI.<init>(SimpleCDI.java:77)
    at org.jboss.weld.environment.WeldProvider$EnvironmentCDI.<init>(WeldProvider.java:45)
    at org.jboss.weld.environment.WeldProvider.getCDI(WeldProvider.java:61)
    at javax.enterprise.inject.spi.CDI.current(CDI.java:60)
    at org.jboss.weld.servlet.WeldInitialListener.contextInitialized(WeldInitialListener.java:94)
    at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.contextInitialized(ForwardingServletListener.java:34)
    at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:65)
    at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:140)
    at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart(ServletContainerInitializersStarter.java:63)
    ... 50 more

Does someone see what is going wrong here?


回答1:


This error appears if you forget the beans.xml file or, as in my case, you have put it in the wrong place. Your beans.xml can have only the root element but must exist.

For a Maven project remember that:

  • context.xml shoud stay in src/main/webapp/META-INF/
  • beans.xml should stay in src/main/resources/META-INF/

I had this problem when I moved an application developed using Glassfish (that doesn't need these files) to Tomcat 7.




回答2:


The problem is that you're using both weld-servlet and weld-servlet-core in your pom. This is causing duplicate class entries as weld-servlet is an aggregate of weld-servlet-core. Removing the weld-servlet-core dependency fixed the singleton not set error.

Now, when I did that, I received errors about JSF but that may be other configuration issues.



来源:https://stackoverflow.com/questions/36165668/exception-using-weld-cdi-with-jetty-singleton-not-set-for-static-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!