Jetty: adding <resource-env-ref> programmatically

心已入冬 提交于 2019-12-12 09:18:38

问题


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:

  • http://osdir.com/ml/java.jetty.support/2007-02/msg00198.html
  • http://docs.codehaus.org/display/JETTY/JNDI

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, "/*" );

回答1:


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).



来源:https://stackoverflow.com/questions/5606327/jetty-adding-resource-env-ref-programmatically

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