当前位置: 首页 > 知识库问答 >
问题:

SOA服务使用spring获取空ejb实例

马弘和
2023-03-14

我有一个maven项目,它实现了ApacheCxfWeb服务和一个ejb对象,我正在尝试使用spring注入ejb实例,当我运行程序时,spring容器将ejb bean返回为null。我不明白如何将ejb实现与Springbean联系起来。

该项目有一个apache cxf实现,如下所示:

服务绑定

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

它还有一个spring配置,以实现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>

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

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

如何实例化ejb对象?

共有1个答案

欧阳安晏
2023-03-14

这是我以前用作POC部分的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: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>

然后注射豆子,如下所示。

@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的,您可能需要根据应用服务器进行相应更改

 类似资料:
  • 我有一个postConstruct方法: 方法: VisitService: 方法: 为什么添加服务层会产生此错误?在服务层,我只导致dao方法。

  • 面向服务的体系结构(英文:Service Oriented Architecture)是一种设计模式。 它旨在通过协议为其他应用程序提供服务。 它只是一个概念,不依赖于任何编程语言或平台。 Web services差不多是SOA的一种技术。 服务 服务是定义明确的自包含功能,代表功能单元。 服务可以从另一个服务交换信息。 它不依赖于另一个服务的状态。 服务连接 下图给出了面向服务的体系结构。 服务

  • 我对尝试将微服务/SOA作为一种体系结构非常感兴趣,并且很难对服务之间的集成进行概念化。 我喜欢使用消息传递将客户端与服务分离的想法,但不理解系统如何独占地使用它。典型的异步操作和发布/订阅显然是有意义的——比如创建新订单、广播数据以进行报告等。我不明白的是,人们是否通常尝试在常见的请求/回复场景中使用消息传递——例如,用户点击他们的“个人资料”页面,而需要在页面上呈现的部分数据来自用户服务。 我

  • 这是请求 我试图在我的应用程序中使用上面的ejb 1) 包含JDBC语句2018-03-27 16:28:17,683:错误:http-nio-6180-exec-1:BatchingBatch.PerformExecution:HHH000315:Exception执行批处理[java.sql.BatchUpdateException:batch entry 0 insert into TEAM

  • 我是Java world和Spring Boot的新手,我正在尝试通过注释访问位于YAML文件中的一些配置值。 但是每当我试图访问服务中任何地方的配置值时,我得到的是一个空值。 下面是配置类: 使用它的验证器服务: 我还在主类中添加了注释。

  • 我使用zuul服务作为我所有微服务的API网关。 在zuul filter中,我可以获得如下请求URL: 这里是requestUrl:http://localhost:8052/api/userservice/users 在用户服务中,当我试图使用HttpServletRequest在spring boot rest controller中获取请求URL时: 这里是requestUrl:http: