将EJB注入到servlet中 [英] Injecting EJB into servlet

查看:147
本文介绍了将EJB注入到servlet中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有运气googled试图理解为什么Weblogic 10.3.4不会将EJB注入到servlet的注释字段中。

I googled without luck trying to understand why Weblogic 10.3.4 does not inject EJB into annoted field in servlet.

Ear包含定义DAO EJB和Web的ejb.jar .war with TestServlet。

Ear contains ejb.jar defining DAO EJB and web.war with TestServlet.

PluginDataDAO.java

@Stateless
public class PluginDataDAO implements IPluginDataDAO {

}

IPluginDataDAO.java

@Local
public interface IPluginDataDAO  {

}

TestServlet.java

public class TestServlet extends HttpServlet {
    @EJB(mappedName = "PluginDataDAO")
    private IPluginDataDAO pluginDataDAO;
}

web.xml

<web-app version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID">
<servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>cz.literak.blog.j2ee.TestServlet</servlet-class>
</servlet>

Servlet位于web.war中,ejb.jar中的EJB。我尝试使用/没有映射名称属性的注释没有运气。当我尝试将web.xml升级到3.0时,部署失败,3.0不是枚举的。哪里不对?为什么pluginDataDAO仍然为空?谢谢。

Servlet is inside web.war, EJB in ejb.jar. I tried the annotation with/without mapped name attribute without luck. When I tried to upgrade web.xml to 3.0, deployment failed that 3.0 is not enumerated. What is wrong? Why is pluginDataDAO still null? Thank you.

推荐答案

以下组合工作:

Servlet

@EJB
private IPluginDataDAO pluginDataDAO;

web.xml

...
  <ejb-local-ref>
    <ejb-ref-name>PluginDataDAO</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>cz.literak.blog.j2ee.dao.IPluginDataDAO</local>
  </ejb-local-ref>
...

我以为添加对web.xml的引用不是必需的有什么规则,何时添加?

I thought that adding references to web.xml is not neccessary .. What are the rules, when to add them?

这篇关于将EJB注入到servlet中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆