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

Jan-Willem Gmelig Meyling picture Jan-Willem Gmelig Meyling · Mar 22, 2016 · Viewed 8.1k times · Source

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?

Answer

xonya picture xonya · May 18, 2016

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.