Jetty + Jersey Servlet + Weld:焊缝注射未初始化,怎么了? [英] Jetty+Jersey servlet+Weld: Weld injection not initialized, what is wrong?
问题描述
我正试图从Glassfish + Jersey + Weld迁移到Jetty.
我有这样的设置: pom.xml,web.xml和Java启动器的要领.
应用程序似乎可以正常启动,但是在处理任何请求时,我看到应该由Weld(logger
)注入的字段为空.
@RequestScoped
@Path("/foobar")
@Consumes({ ExtendedMediaType.APPLICATION_JSON,
ExtendedMediaType.APPLICATION_JAVASCRIPT })
@Produces({ ExtendedMediaType.APPLICATION_JSON,
ExtendedMediaType.APPLICATION_JAVASCRIPT })
public class EmailResource extends {
@Inject
private Logger logger;
@Override @POST
public Response create(EmailJob document)
throws URISyntaxException, ResourceException
{
logger.debug("Hi there!");
}
}
出什么问题了?
更新:Logger生产者看起来可疑,但甚至没有得到称呼:
/** This class uses CDI to alias Java EE resources into CDI beans. **/
public class Resources {
@Produces
public Logger produceLog(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(
injectionPoint.getMember().getDeclaringClass().getName());
}
}
维克多,我的要求是我的要求,我已经 github . /p>
我的主旨没有发现任何问题,但是您可以显示Logger生产者吗?
更新:
我在您的代码中看到一个错字"BeanMnanager",但不确定是否是原因
new Resource("BeanManager", new Reference("javax.enterprise.inject.spi.BeanMnanager",
"org.jboss.weld.resources.ManagerObjectFactory", null));
I'm trying to migrate from Glassfish+Jersey+Weld to Jetty.
I have such a setup: gist of pom.xml, web.xml and Java launcher.
Application seems to start fine, but when serving any request I see that the field that should be injected by Weld (logger
) is null.
@RequestScoped
@Path("/foobar")
@Consumes({ ExtendedMediaType.APPLICATION_JSON,
ExtendedMediaType.APPLICATION_JAVASCRIPT })
@Produces({ ExtendedMediaType.APPLICATION_JSON,
ExtendedMediaType.APPLICATION_JAVASCRIPT })
public class EmailResource extends {
@Inject
private Logger logger;
@Override @POST
public Response create(EmailJob document)
throws URISyntaxException, ResourceException
{
logger.debug("Hi there!");
}
}
What is the problem?
update: Logger producer looks dubious, but it doesn't even get called:
/** This class uses CDI to alias Java EE resources into CDI beans. **/
public class Resources {
@Produces
public Logger produceLog(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(
injectionPoint.getMember().getDeclaringClass().getName());
}
}
Hi Victor my answer as requested, I've blogged about this with embedded jetty. I've also pushed a fully working example to github that you can clone.
I don't see anything wrong in your gist, however could you show your Logger producer?
UPDATE:
I see a typo "BeanMnanager" in your code, but not sure if it is the cause
new Resource("BeanManager", new Reference("javax.enterprise.inject.spi.BeanMnanager",
"org.jboss.weld.resources.ManagerObjectFactory", null));
这篇关于Jetty + Jersey Servlet + Weld:焊缝注射未初始化,怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!