CDI注入点@httpparam问题
我遵循 Weld 的文档 第 4.11 节。 InjectionPoint 对象
有一个非常有趣的示例,介绍如何使用 CDI 获取 http 参数,
但我将代码复制粘贴到 netbeans 中,所有内容都可以编译,但出现部署错误
原因为:org.jboss.weld.exceptions.DeploymentException:WELD -001408 注入点具有不满足的依赖性。注入点:java.lang.String com.test.HttpParamProducer.getParamValue(javax.enterprise.inject.spi.InjectionPoint,javax.servlet.ServletRequest)的参数1;限定符:[@javax.enterprise.inject.Default()]
如何解决这个问题???
public class HttpParamProducer {
@HttpParam("")
@Produces
String getParamValue(
InjectionPoint ip, ServletRequest request) {
return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
}
}
I follow the Weld's doc
in the section 4.11. The InjectionPoint object
There is a very interesting example about how to obtain the http parameter using CDI
but i copy-pasted the code into netbeans, everything compiles, but has an deployment error
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Injection point has unsatisfied dependencies. Injection point: parameter 1 of java.lang.String com.test.HttpParamProducer.getParamValue(javax.enterprise.inject.spi.InjectionPoint,javax.servlet.ServletRequest); Qualifiers: [@javax.enterprise.inject.Default()]
how to solve this problem???
public class HttpParamProducer {
@HttpParam("")
@Produces
String getParamValue(
InjectionPoint ip, ServletRequest request) {
return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
生产者方法上的每个参数都会被注入,并且您的任何 Bean(包括生产者)都不会提供 API 类型 ServletRequest 来满足此注入点。
Every parameter on a producer method is injected, and none of your beans (including producers) provides the API type ServletRequest to satisfy this injection point.
似乎两年后,这个问题仍然令人感兴趣
,这是 CDI 规范的一个缺点,它不需要容器将 HttpServletRequest 作为可注入 bean 公开,
这里是一个合理的解决方法
,现在 @Inject HttpServletRequest 将工作为期待
快乐的编码
it seems that after two years, this question is still interested
this is a short coming of the CDI spec, where it doesn't require the container to expose HttpServletRequest as injectable bean
here is a reasonable work around
now @Inject HttpServletRequest will be working as expected
happy coding