码头:添加< resource-env-ref>以编程方式 [英] Jetty: adding <resource-env-ref> programmatically
问题描述
我有一个带有嵌入式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, "/*" );
以编程方式添加resource-env-ref没有任何意义. JavaEE引用的重点是将开发人员与部署人员分开:开发人员声明了引用,部署人员将引用绑定到环境中的托管资源.如果您没有或不需要部署者角色,那么您也不需要resource-env-ref:只需自己查找目标对象(对于CDI集成,我认为这将是@Produces方法). /p>
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, "/*" );
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).
这篇关于码头:添加< resource-env-ref>以编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!