2

我想将 Web 应用程序(gwt,jpa)合并到一个单独的 2 个应用程序(ejb/jpa 中的业务登录和 gwt 中的 Web 客户端)。目前我无法从 Web 应用程序(简单的 servlet)注入我的 bean

我正在使用 glassfish v3。模块limbo(ejb jar)依赖于模块lust(战争)。

如果我使用 lust 的编译器输出的 lust 一切正常(如果 web 应用程序中的 ejb 并且作为一个应用程序一起部署)。

我弄乱了一些容器配置吗?

这是我的步骤:

我有一些limbo.jar(ejb-jar)部署到ejb容器。我不使用任何 ejb-jar.xml,只使用注释。


package ua.co.inferno.limbo.persistence.beans;

import javax.ejb.Remote;

@Remote
public interface IPersistentServiceRemote {
ArrayList<String> getTerminalACPList();

ArrayList<String> getBoxACPList();

ArrayList<String> getCNPList();

ArrayList<String> getCNSList();

String getProductNamebyID(int boxid);

ArrayList<String> getRegionsList(String lang);

long getSequence();    

void persistEntity (Object ent);
}

package ua.co.inferno.limbo.persistence.beans;

import ua.co.inferno.limbo.persistence.entitis.EsetChSchemaEntity;
import ua.co.inferno.limbo.persistence.entitis.EsetKeyActionsEntity;
@Local
public interface IPersistentService {
ArrayList<String> getTerminalACPList();

ArrayList<String> getBoxACPList();

ArrayList<String> getCNPList();

ArrayList<String> getCNSList();

String getProductNamebyID(int boxid);

ArrayList<String> getRegionsList(String lang);

long getSequence();

long persistPurchaseBox(EsetRegPurchaserEntity rp);

void removePurchaseTempBox(EsetRegPurchaserTempEntity rpt);

EsetRegionsEntity getRegionsById(long rid);

void persistEntity (Object ent);
}

package ua.co.inferno.limbo.persistence.beans;

import ua.co.inferno.limbo.persistence.entitis.EsetChSchemaEntity;
import ua.co.inferno.limbo.persistence.entitis.EsetKeyActionsEntity;
import ua.co.inferno.limbo.persistence.entitis.EsetRegBoxesEntity;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless(name = "PersistentService")
public class PersistentServiceEJB
    implements
    IPersistentService, IPersistentServiceRemote{
@PersistenceContext(unitName = "Limbo")
EntityManager em;

public PersistentServiceEJB() {
}
.........
}

比我尝试从 lust.war 中的 Web 应用程序使用 PersistentService 会话 bean(包含在limbo.jar 中)(limbo.jar 和 lust.war不在 ear 中


package ua.co.lust;

import ua.co.inferno.limbo.persistence.beans.IPersistentService;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ServletTest",
    urlPatterns = {"/"})
public class ServletTest extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws            ServletException, IOException {

    service(request, response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    service(request, response);
}



@EJB
private IPersistentService pService;


public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String hi = pService.getCNPList().toString();

    System.out.println("testBean.hello method returned: " + hi);
    System.out.println("In MyServlet::init()");
    System.out.println("all regions" + pService.getRegionsList("ua"));
    System.out.println("all regions" + pService.getBoxACPList());


    }
 }

网页.xm


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
           version="3.0">

    <servlet>
        <servlet-name>ServletTest</servlet-name>
        <servlet-class>ua.co.lust.ServletTest</servlet-class>
    </servlet>

</web-app>

当servelt正在加载i ge 404错误(请求的资源()不可用。)

和日志中的错误:

全球的

Log Level
SEVERE
Logger
global
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=31}
Record Number
1421
Message ID
Complete Message
Class [ Lua/co/inferno/limbo/persistence/beans/IPersistentService; ] not found. Error while loading [ class ua.co.lust.ServletTest ]

javax.enterprise.system.tools.deployment.org.glassfish.deployment.common

Log Level
WARNING
Logger
javax.enterprise.system.tools.deployment.org.glassfish.deployment.common
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=31}
Record Number
1422
Message ID
Error in annotation processing
Complete Message
java.lang.NoClassDefFoundError: Lua/co/inferno/limbo/persistence/beans/IPersistentService;

ejb jar 使用此信息日志部署:


Log Level
INFO
Logger
javax.enterprise.system.container.ejb.com.sun.ejb.containers
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=26}
Record Number
1436
Message ID
Glassfish-specific (Non-portable) JNDI names for EJB PersistentService
Complete Message
[ua.co.inferno.limbo.persistence.beans.IPersistentServiceRemote#ua.co.inferno.limbo.persistence.beans.IPersistentServiceRemote, ua.co.inferno.limbo.persistence.beans.IPersistentServiceRemote]

Log Level
INFO
Logger
javax.enterprise.system.tools.admin.org.glassfish.deployment.admin
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=26}
Record Number
1445
Message ID
Complete Message
limbo was successfully deployed in 610 milliseconds.

如果从其他应用程序注入,我是否需要添加一些额外的配置?

一些想法?


在@Remote 的情况下

package ua.co.lust;

import ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ServletTest",
        urlPatterns = {"/"})
public class WebTestServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        service(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        service(request, response);
    }


//    @EJB
//    private PersistentServiceRemote pService;   <<-- DI not working :( - same errs as with Local interface (class not found)

    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {

        Context ctx = null;
        try {
            ctx = new InitialContext();
            PersistentServiceRemote pService =
                    (PersistentServiceRemote) ctx.lookup("java:global/limbo/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote");

            String hi = pService.getCNPList().toString();


            System.out.println("testBean.hello method returned: " + hi);
            System.out.println("In MyServlet::init()");
            System.out.println("all regions" + pService.getRegionsList("ua"));
            System.out.println("all regions" + pService.getBoxACPList());

        } catch (NamingException e) {
            e.printStackTrace();
        }


    }
}

日志 :

        Log Level
        SEVERE
        Logger
        javax.enterprise.system.std.com.sun.enterprise.v3.services.impl
        Name-Value Pairs
        {_ThreadName=Thread-1, _ThreadID=32}
        Record Number
        1963
        Message ID
        javax.naming.NamingException
        Complete Message
        Lookup failed for 'java:global/limbo/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote' in SerialContext [Root exception is javax.naming.NamingException: ejb ref resolution error for remote business 
    interfaceua.co.inferno.limbo.persistence.beans.PersistentServiceRemote [Root exception is java.lang.ClassNotFoundException: ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote]] at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442) at 
    javax.naming.InitialContext.lookup(InitialContext.java:392) at javax.naming.InitialContext.lookup(InitialContext.java:392) at 
ua.co.lust.WebTestServlet.service(WebTestServlet.java:45) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at 
    com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipel
ine.java:85) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) at 
    org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at 
    com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at 
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at 
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at 
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at 
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:619) Caused by: javax.naming.NamingException: ejb ref resolution error for remote business interfaceua.co.inferno.limbo.persistence.beans.PersistentServiceRemote [Root exception is java.lang.ClassNotFoundException: ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote] at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:430) at 
com.sun.ejb.containers.RemoteBusinessObjectFactory.getObjectInstance(RemoteBusinessObjectFac
tory.java:70) at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304) at 
com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:472) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:437) ... 28 more 
Caused by: java.lang.ClassNotFoundException: ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at 
java.net.URLClassLoader.findClass(URLClassLoader.java:188) at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:959) at 
org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1430) at com.sun.ejb.EJBUtils.getBusinessIntfClassLoader(EJBUtils.java:678) at 
com.sun.ejb.EJBUtils.loadGeneratedRemoteBusinessClasses(EJBUtils.java:459) at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:410) ... 32 more

信息部署日志

Log Level
INFO
Logger
javax.enterprise.system.container.ejb.com.sun.ejb.containers
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=11}
Record Number
1899
Message ID
Portable JNDI names for EJB PersistentServiceBean
Complete Message
[java:global/limbo/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote, java:global/limbo/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceLocal]

如果我使用远程业务逻辑调用,是否需要将我的 ejb jar 包含到 WEB=INF/lib 中?为什么 DI 在远程情况下不起作用?

如果我包含来自limbo模块的编译输出并提供:

PersistentServiceRemote pService =
                    (PersistentServiceRemote) ctx.lookup("java:global/lust/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote");

为什么我无法为另一个 Web 应用程序查找 PersistentServiceRemote(PersistentServiceBean 的远程接口)?

通过 glassfish 的示例代码它应该可以工作 (.

有任何想法吗?


行。正如帕斯卡所说。我们需要在 webapp 中打包远程接口。我们可以在不同的应用程序中使用本地接口注入。如果您需要使用本地接口,您需要在您的应用程序中包含 ejb jar。当前设计 - 将远程接口打包到 webapp

4

1 回答 1

1

如果您不将 ejb-jar 部署为您的战争库(即在 WEB-INF/lib 下),我认为您将无法使用本地接口(并且您必须将webapp 中的远程接口)。

PS:你真的不需要web.xml这里。

于 2010-03-28T20:25:02.633 回答