【问题标题】:Inject EJB 3.0 in spring 2.0 controller on websphere is throwing exception在 websphere 上的 spring 2.0 控制器中注入 EJB 3.0 抛出异常
【发布时间】:2016-07-22 19:20:19
【问题描述】:

我想从我的 spring bean 中调用 EJB 服务。我已经尝试了很多类似下面的方法并部署在 websphere 上,但它在 jndi 名称中给了我例外。任何人都可以帮忙吗?

春豆

<?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)

【问题讨论】:

  • 这可能对你有帮助 - stackoverflow.com/questions/23008810/…
  • 其实和我做的一样,但它给了我上面的异常
  • 您的 EJB 显然没有使用名称 ejb/EjbServiceImpl 绑定。 SystemOut.log 中的 CNTR0167I 消息应该告诉您应该使用哪个绑定名称。
  • 尝试在控制器类中用@EJB注释“private EjbService eService”
  • 在您的EjbServiceImpl 上,您应该有@Stateless(mappedName = "ejb/EjbServiceImpl")。然后,您可以像现在一样引用您的 EJB:&lt;property name="jndiName" value="ejb/EjbServiceImpl"&gt;

标签: spring websphere ejb-3.0


【解决方案1】:

感谢所有试图帮助我的人,实际上通过以下方式解决了我的问题

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);
    }   
}

【讨论】:

    猜你喜欢
    • 2019-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多