SOA服务使用spring获取null ejb实例 [英] SOA service gets null ejb instance using spring

查看:136
本文介绍了SOA服务使用spring获取null ejb实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maven项目实现apache cxf web服务和ejb对象,我试图使用spring注入ejb实例,当我运行程序时,spring容器将ejb bean返回为空。我不明白如何将ejb实现与spring bean相关联。



该项目有一个apache cxf实现,这样:



ServiceBindingImpl

  @WebService(endpointInterface =cl.flying.binding.ServiceBinding)
public class ServiceBindingImpl实现ServiceBinding {
private ServiceBusinessLocal serviceEjb
public void setServiceEjb(ServiceBusinessLocal serviceEjb ){
this.serviceEjb = serviceEjb
}
public String sayHello(String request){
return serviceEjb.sayHello(request);
}
}



它还有一个弹簧配置订单实现DI,applicationContext.xml

 < bean id =serviceEjb
class =org.springframework .ejb.access.LocalStatelessSessionProxyFactoryBeanscope =request>
< property name =jndiNamevalue =ejb / ServiceBusinessImpl/>
< property name =businessInterfacevalue =cl.service.business.ServiceBusinessLocal/>
< property name =resourceRefvalue =true/>
< / bean>
< bean id =ServiceControllerclass =cl.flying.binding.ServiceBindingImpl>
< property name =serviceEjbref =serviceEjb/>
< / bean>



这是业务层,无状态ejb实现:

  @Stateless(mappedName =ejb / ServiceBusiness)
public class ServiceBusinessImpl实现ServiceBusinessLocal
public String sayHello(String request ){
returnhello:+ request;
}
}



如何实例化ejb对象?

解决方案

以下是我用作部分POC的bean配置文件。

 <?xml version =1.0encoding =UTF-8?> 
< beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xmlns:jee =http://www.springframework.org/schema/jee
xmlns:util =http://www.springframework.org/schema/util
xmlns :context =http://www.springframework.org/schema/context
xsi:schemaLocation =http://www.springframework.org/schema/jee http://www.springframework.org/ schema / jee / spring-jee-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema / util http://www.springframework.org/schema/util/spring-util-4.2.xsd\">

< jee:remote-slsb id =calculatorRemotebusiness-interface =com.kp.swasthik.remote.CalculatorRemotejndi-name =java:kp-ejb / Calculator! kp.swasthik.remote.CalculatorRemotelookup-home-on-startup =true>
< jee:environment>
java.naming.factory.initial = org.jboss.naming.remote.client.InitialContextFactory
java.naming.provider.url = http-remoting:// localhost:8080
jboss。 naming.client.ejb.context = true
java.naming.security.principal = username
java.naming.security.credentials = password
< / jee:environment>
< / jee:remote-slsb>

< context:component-scan base-package =com.kp.swasthik.jaxws>< / context:component-scan>

< util:properties id =remoteRef>
< prop key =java.naming.factory.initial> org.jboss.naming.remote.client.InitialContextFactory< / prop>
< prop key =java.naming.provider.url> remote:// localhost:4447< / prop>
< prop key =java.naming.factory.url.pkgs> org.jboss.ejb.client.naming< / prop>
< / util:properties>

< / beans>

并注入如下所示的bean。

  @Service 
@WebService
public class KPService {

@Autowired
CalculatorRemote calc;

@WebMethod
public int add(int a,int b){
return calc.add(a,b);
}


@WebMethod
public Result subtract(Input num){
return calc.subtract(num);
}

}

注意:以上配置用于Wildfly / JBOSS EAP,您可能需要相应地更改为您的应用服务器


I have a maven project that implements apache cxf web service and a ejb object, I'm trying inject the ejb instance using spring, when I run the program, the spring container returns the ejb bean as a null. I don't understand how to relate the ejb implementation with the spring bean.

The project has a apache cxf implementation, this way:

ServiceBindingImpl

@WebService(endpointInterface = "cl.flying.binding.ServiceBinding")
public class ServiceBindingImpl implements ServiceBinding { 
    private ServiceBusinessLocal serviceEjb
    public void setServiceEjb(ServiceBusinessLocal serviceEjb) {
        this.serviceEjb = serviceEjb
    }
    public String sayHello(String request) {
        return serviceEjb.sayHello(request);
    }
}

It also has a spring configuration in order to achieve DI, applicationContext.xml

<bean id="serviceEjb"
    class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean" scope="request">
    <property name="jndiName" value="ejb/ServiceBusinessImpl" />
    <property name="businessInterface" value="cl.service.business.ServiceBusinessLocal" />
    <property name="resourceRef" value="true" />
</bean>
<bean id="ServiceController" class="cl.flying.binding.ServiceBindingImpl">
    <property name="serviceEjb" ref="serviceEjb" />
</bean>

That is the business tier, Stateless ejb implementation:

@Stateless(mappedName="ejb/ServiceBusiness")
public class ServiceBusinessImpl implements ServiceBusinessLocal
    public String sayHello(String request) {
        return "hello: " + request;
    }
}

How can I instantiate the ejb object?

解决方案

Here is the bean configuration file I used as part POC sometime back

<?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:jee="http://www.springframework.org/schema/jee"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

    <jee:remote-slsb id="calculatorRemote" business-interface="com.kp.swasthik.remote.CalculatorRemote" jndi-name="java:kp-ejb/Calculator!com.kp.swasthik.remote.CalculatorRemote" lookup-home-on-startup="true" >
        <jee:environment>
             java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
             java.naming.provider.url=http-remoting://localhost:8080
             jboss.naming.client.ejb.context=true
             java.naming.security.principal=username
             java.naming.security.credentials=password
        </jee:environment>
    </jee:remote-slsb>

    <context:component-scan base-package="com.kp.swasthik.jaxws"></context:component-scan>

    <util:properties id="remoteRef">
        <prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory</prop>
        <prop key="java.naming.provider.url">remote://localhost:4447</prop>
        <prop key="java.naming.factory.url.pkgs">org.jboss.ejb.client.naming</prop>
    </util:properties>

</beans>

And injecting the bean as shown below.

@Service
@WebService
public class KPService {

    @Autowired
    CalculatorRemote calc;

    @WebMethod
    public int add(int a, int b){
        return calc.add(a, b);
    }


    @WebMethod
    public Result subtract(Input num){
         return calc.subtract(num);
    }

}

NOTE: The above configuration is for Wildfly/JBOSS EAP, you might need to change accordingly to your app server

这篇关于SOA服务使用spring获取null ejb实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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