使用企业 Java Bean 提升
我在使用企业 java bean 部署 lift 应用程序时遇到了麻烦。有一个简单的例子:
@Stateless
class TestEJB {
def a = "hello"
}
object TestApi extends XMLApiHelper{
@EJB
private var bean:TestEJB = _
def createTag(a:NodeSeq) =
def dispatch: LiftRules.DispatchPF = {
case Req("test" :: Nil, "", GetRequest) =>
() => PlainTextResponse( bean.a )
}
}
bean.a
线上出现 NullPointerException,这意味着 bean
尚未初始化好。为什么?
I have troubles with deploying lift application with uses enterprise java beans. There's a simple example:
@Stateless
class TestEJB {
def a = "hello"
}
object TestApi extends XMLApiHelper{
@EJB
private var bean:TestEJB = _
def createTag(a:NodeSeq) =
def dispatch: LiftRules.DispatchPF = {
case Req("test" :: Nil, "", GetRequest) =>
() => PlainTextResponse( bean.a )
}
}
There's NullPointerException on line with bean.a
, so that means, that the bean
haven't been initialized well. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不支持 Lift,但 @EJB 标准仅适用于 servlet、过滤器、上下文侦听器、jsf 托管 bean、ejbs、webbean 和其他 Java EE 组件。注意,JSP 类由于其动态生成/编译,不符合使用 @EJB 的条件,并且必须查找 EJB,即使它们在运行时在技术上算作 servlet。
作为注入的替代方法,您可以使用查找。如果您在 Java EE 6 服务器中,任何 java 代码都可以通过其标准“java:global”JNDI 名称查找 EJB。
Not Lift-aware, but @EJB is standardly only available to servlet, filter, context listener, jsf managed beans, ejbs, webbeans and other Java EE components. Note JSP classes, due to their dynamic generation/compilation, are not eligible to use @EJB and have to instead lookup EJBs even though they technically count as a servlet at runtime.
As an alternative to injection you could use lookup. If you are in a Java EE 6 server any java code can lookup the EJB via its standard "java:global" JNDI name.