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

2

9

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?

Egger answered 22/3, 2016 at 21:34 Comment(6)
Did you mind the /WEB-INF/beans.xml file?Discharge
This is my WEB-INF/beans.xml : <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" xmlns.jcp.org/xml/ns/javaee xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all"> </beans>Egger
Problem suggests BeanManager can't be found. Which Jetty version is it? 9.2.4+ allows an easier way of configuring: eclipse.org/jetty/documentation/current/framework-weld.htmlDischarge
See my version numbers and other configuration in the following gist: gist.github.com/JWGmeligMeyling/529250b4387c4b6103aa . I try to be on the newest version.Egger
@Jan-WillemGmeligMeyling, did you resolve your problem?Disputatious
No I transitioned from a servlet container (Jetty) to a J2EE server (Wildfly)Egger
D
6

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.

Dru answered 18/5, 2016 at 7:26 Comment(0)
R
1

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.

Rainier answered 23/3, 2016 at 0:3 Comment(2)
I got to this point because I needed the org.omnifaces.resourcehandler.CombinedResourceHandler for Bootsfaces, so I started to add Omnifaces. Then it turned out I needed CDI, so I added weld. Right now I try to find matching versions for weld, jsf, etc.etc. so I can get the configuration to work in my test runner, the jetty-maven-plugin. I am actually starting to believe that such a configuration does simply not exist, as I keep running into other exceptions. Could you perhaps have a look at the "other configration issues"?Egger
See also #27667181 and github.com/skaterkamp/streichelzoo-faces/blob/master/…Egger

© 2022 - 2024 — McMap. All rights reserved.