Jetty:添加以编程方式
我有一个带有嵌入式 Jetty 和 Wicket 的独立应用程序。
我想使用CDI进行注射。
所以我找到了 http://docs。 jboss.org/weld/reference/latest/en-US/html/environments.html#d0e5286
现在我尝试以编程方式添加它,但它非常复杂。
如何编码?
我发现的其他来源是:
- http://osdir.com/ml/java.jetty.support/2007-02/msg00198.html
- http://docs.codehaus.org/display/JETTY/JNDI
到目前为止,我有:
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, "/*" );
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, "/*" );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以编程方式添加资源环境引用没有意义。 JavaEE 引用的要点是将开发人员与部署人员分开:开发人员声明一个引用,部署人员将该引用绑定到环境中的托管资源。如果您没有或不需要部署者角色,那么您也不需要资源环境引用:只需自己查找目标对象(对于 CDI 集成,我认为这将是一个 @Produces 方法)。
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).