2016-04-03 36 views
0

我想从我的spring bean中调用EJB服务。我已经尝试了许多方法,像下面这样在websphere上部署,但它在jndi名称中给我例外。谁能帮忙?在websphere的spring 2.0控制器中注入EJB 3.0引发异常

的Spring bean

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"> 


<bean id="ejbService" class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean"> 
     <property name="jndiName" value="ejb/EjbServiceImpl"/> 
     <property name="businessInterface" value="com.services.EjbService"/> 
    </bean> 
<bean id="springController" class="com.controllers.SpringController" scope="session"> 
    <property name="eService" ref="ejbService"/>     
    </bean> 

</beans> 

春季控制器

public class SpringController { 

    private EjbService eService; 

    public void setOrders(Order order) { 
     eService.liquidPortfolio(order); 
    } 

    public EjbService getEService() { 
     return eService; 
    } 

    public void setEService (
     EjbService eService) { 
     this.eService = eService; 
    } 
} 

EJB

@Local 
public class EjbService { 
    @Asynchronous 
    public void setOrders(Order order) ; 
} 

@Stateless 
@Singleton 
public class EjbServiceImpl implements EjbService{ 

    @PostConstruct 
    public void init() { 
     System.out.println(" init method"); 
    } 

    @Asynchronous 
    public void setOrders(Order order) {   
     System.out.println(" order=" + order); 
    } 
} 

异常

[4/3/16 9:44:30:708 AST] 0000007a ContextLoader E org.springframework.web.context.ContextLoader initWebApplicationContext Context initialization failed 
           org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ejbService' defined in ServletContext resource [/WEB-INF/my-web-context.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Context: WSRUHHQ830Node01Cell/nodes/WSRUHHQ830Node01/servers/server1, name: ejb/EjbServiceImpl: First component in name EjbServiceImpl not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) 

Caused by: javax.naming.NameNotFoundException: Context: WSRUHHQ830Node01Cell/nodes/WSRUHHQ830Node01/servers/server1, name: ejb/EjbServiceImpl: First component in name EjbServiceImpl not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0] 
    at com.ibm.ws.naming.jndicos.CNContextImpl.mapNotFoundException(CNContextImpl.java:4564) 
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1822) 
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1777) 
    at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1434) 
    at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:616) 
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:165) 
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179) 
    at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161) 
    at javax.naming.InitialContext.lookup(InitialContext.java:423) 

Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0 
    at com.ibm.ws.naming.ipcos.WsnOptimizedNamingImpl.do_resolve_complete_info(WsnOptimizedNamingImpl.java:567) 
    at com.ibm.ws.naming.cosbase.WsnOptimizedNamingImplBase.resolve_complete_info(WsnOptimizedNamingImplBase.java:2169) 
    at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve_complete_info(_NamingContextStub.java:538) 
    at com.ibm.ws.naming.jndicos.CNContextImpl$2.run(CNContextImpl.java:2958) 
    at com.ibm.ws.naming.jndicos.CNContextImpl$2.run(CNContextImpl.java:2954) 
    at com.ibm.ws.naming.util.CommonHelpers.retry(CommonHelpers.java:871) 
    at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:2952) 
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1818) 
+0

这可能对你有帮助 - http://stackoverflow.com/questions/23008810/ejb-3-injection-into-spring-beans – Sampada

+0

实际上它和我做的一样,但它给了我上面的例外 –

+0

你的EJB是显然没有使用名称“ejb/EjbServiceImpl”进行绑定。 SystemOut.log中的CNTR0167I消息应该告诉你应该使用哪个绑定名称。 –

回答

0

感谢所有为之努力帮助我,居然解决了我的问题,通过以下方式

的Spring XML

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"> 

<bean id="springController" class="com.controllers.SpringController" scope="session"> 
    <property name="eService" ref="ejbService"/>     
    </bean> 
<jee:jndi-lookup id="ejbService" jndi-name="java:global/myEAR/myApp/EjbService"> 
    </jee:jndi-lookup> 
</beans> 

春季控制器

public class SpringController { 

    private EjbService eService; 

    public void setOrders(Order order) { 
     eService.liquidPortfolio(order); 
    } 

    public EjbService getEService() { 
     return eService; 
    } 

    public void setEService (
     EjbService eService) { 
     this.eService = eService; 
    } 
} 

我的EJB

@LocalBean 
@Stateless 
@Singleton 
public class EjbService { 

    @Asynchronous 
    public void setOrders(Order order) {   
     System.out.println(" order=" + order); 
    } 
}