Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a standalone application with embedded Jetty and Wicket.
I'd like to use CDI for injection.

So I've found http://docs.jboss.org/weld/reference/latest/en-US/html/environments.html#d0e5286
and now I'm trying to add this programatically, but it's quite complex.

How do I code that?

Other sources I've found are:

So far I have:

  Server server = new Server( 8080 );
  Context ctx = new Context( server, "/", Context.NO_SECURITY | Context.SESSIONS );


  try {
     //BeanManager
     new org.mortbay.jetty.plus.naming.Resource( ctx, "BeanManager", 
        new javax.naming.Reference(
           "javax.enterprise.inject.spi.BeanManager",
           "org.jboss.weld.resources.ManagerObjectFactory", null )
     );
  } catch ( NamingException ex ) {
     log.error(...);
  }


  // Wicket.
  final ServletHolder wicketSH = new ServletHolder( new MyReloadingWicketServlet() );
  wicketSH.setInitParameter( "applicationClassName", WicketApplication.class.getName() );
  ctx.addServlet( wicketSH, "/*" );
share|improve this question
    
Maybe I've found - weld-wicket –  Ondra Žižka Apr 9 '11 at 17:00
    
Oh no. Weld-wicket is now seam-wicket, whose docs refer back to weld-wicket's, which only describes XML configuration :( –  Ondra Žižka Apr 10 '11 at 1:19

1 Answer 1

up vote 1 down vote accepted

Adding a resource-env-ref programmatically doesn't make sense. The point of JavaEE refs is to separate the developer from the deployer: the developer declares a reference, and the deployer binds the reference to a managed resource in the environment. If you don't have or need a deployer role, then you don't need a resource-env-ref either: simply look up the target object yourself (for CDI integration, I think that would be an @Produces method).

share|improve this answer
    
Well, you're probably right. I only saw an example in the docs, and was struggling getting it work because Seam-Wicket's Weld JNDI lookup didn't work. In the end, I used someone's patch which stores and get's BeanManager from ServletContext. –  Ondra Žižka Apr 27 '11 at 21:58
    
So, in the end, using JNDI API directly solved this. –  Ondra Žižka May 8 '11 at 13:00
    
@Ondra Žižka can you post your code? I have to solve something very similar –  saberduck Jul 21 '11 at 11:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.