EJB Bean中的Rest + Remote,不起作用

时间:2016-04-20 19:14:54

标签: java ejb glassfish-4

我正在尝试使用远程接口和REST接口(Jersey)构建EJB计算器。

如果未实现ICalcRemote,则REST接口可以正常工作。当我实施ICalcRemote时,它无法正常工作。

你能看一下我的代码吗?我在Glassfish 4.0上运行它。

Calc.java

import javax.ejb.Stateless;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;



@Stateless
@Path("/solve/{x}")
public class Calc implements ICalcRemote{
    public Calc(){
    }
    @GET
    @Produces("text/plain")
    public String calc(@PathParam("x") String math) throws ScriptException{
        math = math.replace("p","+");
        math = math.replace("d", "/");
        if(math.matches("\\d+.\\d+")){
            ScriptEngineManager mgr = new ScriptEngineManager();
            ScriptEngine engine = mgr.getEngineByName("JavaScript");
            //System.out.print(math);
            return engine.eval(math ).toString();
        }
        return "ErrorBean";
    }

}

ICalcRemote

import javax.ejb.Remote;
import javax.script.ScriptException;


@Remote
public interface ICalcRemote {
    String calc(String math)throws ScriptException;
}

Application.java

import javax.ws.rs.ApplicationPath;

@ApplicationPath("/api")
public class Application extends javax.ws.rs.core.Application{
}

控制台错误

Attempting to start domain1.... Please look at the server log for more details.....
Connected to server
[2016-04-20 09:09:59,730] Artifact CalculatorEJB:ejb exploded: Artifact is being deployed, please wait...
[2016-04-20 09:09:59,731] Artifact CalculatorEJB:war exploded: Artifact is being deployed, please wait...
[2016-04-20 09:10:08,158] Artifact CalculatorEJB:ejb exploded: Artifact is deployed successfully
[2016-04-20 09:10:08,158] Artifact CalculatorEJB:ejb exploded: Deploy took 8 428 milliseconds
[2016-04-20 09:10:10,530] Artifact CalculatorEJB:war exploded: Error during artifact deployment. See server log for details.
[2016-04-20 09:10:10,530] Artifact CalculatorEJB:war exploded: java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : EJB Container initialization error. Please see server.log for more details.

GlassFish Log

[2016-04-20T21:10:06.922+0200] [glassfish 4.0] [WARNING] [] [org.jboss.weld.interceptor.util.InterceptionTypeRegistry] [tid: _ThreadID=34 _ThreadName=admin-listener(2)] [timeMillis: 1461179406922] [levelValue: 900] [[
  Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled]]

[2016-04-20T21:10:06.923+0200] [glassfish 4.0] [WARNING] [] [org.jboss.weld.interceptor.util.InterceptionTypeRegistry] [tid: _ThreadID=34 _ThreadName=admin-listener(2)] [timeMillis: 1461179406923] [levelValue: 900] [[
  Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled]]

java.lang.RuntimeException: EJB Container initialization error
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:234)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:291)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:99)
Caused by: java.lang.RuntimeException: Error while binding JNDI name ICalcRemote#ICalcRemote for EJB Calc
    at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1552)
    at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:190)
    at com.sun.ejb.containers.StatelessContainerFactory.createContainer(StatelessContainerFactory.java:63)
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:221)
    ... 38 more
Caused by: javax.naming.NameAlreadyBoundException: Use rebind to override
    at com.sun.enterprise.naming.impl.TransientContext.doBindOrRebind(TransientContext.java:322)
    at com.sun.enterprise.naming.impl.TransientContext.bind(TransientContext.java:257)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.bind(SerialContextProviderImpl.java:85)
    at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.bind(LocalSerialContextProviderImpl.java:94)
    at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:640)
    at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:657)
    at javax.naming.InitialContext.bind(InitialContext.java:423)
    at javax.naming.InitialContext.bind(InitialContext.java:423)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:212)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:196)
java.lang.RuntimeException: EJB Container initialization error
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:234)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:291)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:99)
Caused by: java.lang.RuntimeException: Error while binding JNDI name ICalcRemote#ICalcRemote for EJB Calc
    at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1552)
    at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:190)
    at com.sun.ejb.containers.StatelessContainerFactory.createContainer(StatelessContainerFactory.java:63)
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:221)
    ... 38 more
Caused by: javax.naming.NameAlreadyBoundException: Use rebind to override
    at com.sun.enterprise.naming.impl.TransientContext.doBindOrRebind(TransientContext.java:322)
    at com.sun.enterprise.naming.impl.TransientContext.bind(TransientContext.java:257)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.bind(SerialContextProviderImpl.java:85)
    at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.bind(LocalSerialContextProviderImpl.java:94)
    at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:640)
    at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:657)
    at javax.naming.InitialContext.bind(InitialContext.java:423)
    at javax.naming.InitialContext.bind(InitialContext.java:423)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:212)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:196)
  Exception while loading the app : EJB Container initialization error
java.lang.RuntimeException: Error while binding JNDI name ICalcRemote#ICalcRemote for EJB Calc
    at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1552)
    at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:190)
    at com.sun.ejb.containers.StatelessContainerFactory.createContainer(StatelessContainerFactory.java:63)
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:221)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:291)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:99)

0 个答案:

没有答案