开发者

How do I set up a wicket quickstart to use seam-wicket CDI?

开发者 https://www.devze.com 2023-03-22 05:51 出处:网络
What do I need to do to make CDI work on my wicket quickstart project? When I try to launch the Jetty server, I get an exception:

What do I need to do to make CDI work on my wicket quickstart project? When I try to launch the Jetty server, I get an exception:

org.jboss.seam.solder.beanManager.BeanManagerUnavailableException: Failed to locate BeanManager using any of these providers: org.jboss.seam.solder.beanManager.DefaultJndiBeanManagerProvider(11), org.jboss.seam.solder.beanManager.ServletContainerJndiBeanManagerProvider(10)
at org.jboss.seam.solder.beanManager.BeanManagerLocator.getBeanManager(BeanManagerLocator.java:91)
at org.jboss.seam.wicket.SeamApplication.internalInit(SeamApplication.java:54)
at org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:723)
...

I am authoring a wicket project. I don't know the first thing about Seam, Weld, or CDI; I want to learn it by incorporating it into a small project. I am following this reference documentation:

http://docs.jboss.org/seam/3/wicket/latest/reference/en-US/html_single/

Right now, I am swimming in a sea of alien documentation trying to find the answer. Help!

Edit:

The Jetty server in the wicket quickstart is created programmatically. Based on the documentation given below, I created:

webapp/WEB-INF/jetty-env.xml:

<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
   "http://jetty.mortbay.org/configure.dtd">
<Configure id="webAppCtx" class="org.mortbay.jetty.webapp.WebAppContext">
   <New id="BeanManager" class="org.mortbay.jetty.plus.naming.Resource">
      <Arg><Ref id="webAppCtx"/></Arg> 
      <Arg>BeanManager</Arg>
      <Arg>
         <New class="javax.naming.Reference">
            <Arg>javax.enterprise.inject.spi.BeanManager</Arg> 
            <Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
            <Arg/>
         </New>
      </Arg>
   </New>
</Configure>

In web.xml, I have added the following snippet:

<resource-env-ref>
    <resource-env-ref-name>BeanManager</resource-env-ref-name>
    <resource开发者_开发技巧-env-ref-type>
javax.enterprise.inject.spi.BeanManager
    </resource-env-ref-type>
</resource-env-ref>

<listener>
    <listener-class>org.jboss.seam.solder.resourceLoader.servlet.ResourceListener</listener-class>
</listener>

The following Java code is responsible for setting up the Jetty server in the quickstart environment, when Start is run:

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.setConnectors(new Connector[] { connector });

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");
    // FIXME: This doesn't seem to do anything? bb.addEventListener(new ResourceListener());
    server.addHandler(bb);

/* I don't know what this commented code does, but it doesn't fix the problem when uncommented. */
// START JMX SERVER
// MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
// MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
// server.getContainer().addEventListener(mBeanContainer);
// mBeanContainer.start();

I am using jetty version 6.1.25, according to my Maven Dependencies.


The 42Lines folks have published a Wicket-CDI integration library that includes a working example project.

Several of these guys are actually Wicket committers; they write good code, and they know what they're doing.


In a servlet container you need to bootstrap Weld CDI yourself to make it available to Seam. The documentation states this under installation:
http://docs.jboss.org/seam/3/wicket/latest/reference/en-US/html_single/#wicket.installation

With a link to the relative Weld bootstrapping documentation for either Jetty 6 or 7:

http://docs.jboss.org/weld/reference/latest/en-US/html/environments.html#d0e5286

It should work fine after configuring Jetty to bootstrap Weld. However please take not of the limitations of using Weld within a servlet container:
http://docs.jboss.org/weld/reference/latest/en-US/html/environments.html#d0e5221

Also ensure that you have an empty (or configured) beans.xml in your WEB-INF/ directory.

0

精彩评论

暂无评论...
验证码 换一张
取 消