Spring ServletEndpointSupport整合Axis

使用Spring开发Axis web service服务器端

(那一套都是自动生成的,Locator,Service,ServiceImpl,Stub,Skeleton等等)

现需要在ServiceImpl中添加自己的逻辑,并且需要Spring中的Bean

我是使Skeleton继承了ServletEndpointSupport去获得Bean,在客户端调用(另一项目组)时发现获取不到Bean

但是如果自己使用Spring的ApplicationContext能够加载到(自己写了个main方法进行模拟客户端测试就能够获取)

Spring-references.pdf中有文字如下:

Our AccountServletEndpoint needs to run in the same web application as the Spring context to allow for
access to Spring's facilities. In case of Axis, copy the AxisServlet definition into your 'web.xml', and set up
the endpoint in 'server-config.wsdd' (or use the deploy tool). See the sample application JPetStore where the
OrderService is exposed as a web service using Axis.

我得理解是:只有调用该服务的客户端跟服务器端是跑在同一个上下文中才能使用Spring那一套东西。

真实情况是这样么?如果是那是不是有点太悲剧了,大部分客户端和服务器端还是不在同一个context中的吧?

怎样保证由客户端发起的web service调用能够获取到Spring容器中的Bean呢?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现Spring Boot整合Axis实现WebService服务端,可以按照以下步骤进行: 1. 添加Axis依赖 在pom.xml文件中添加以下Axis依赖: ```xml <dependency> <groupId>axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> ``` 2. 配置Axis ServletSpring Boot的配置类中添加以下Servlet配置: ```java @Bean public ServletRegistrationBean<AxisServlet> axisServlet() { AxisServlet servlet = new AxisServlet(); ServletRegistrationBean<AxisServlet> registration = new ServletRegistrationBean<>(servlet, "/services/*"); registration.addInitParameter("axis.servicesPath", "/services"); registration.addInitParameter("axis.wsddPath", "classpath:wsdd/AxisServlet.wsdd"); return registration; } ``` 这样就可以将Axis Servlet注册到Spring Boot中,并通过"/services/*"路径映射到WebService服务。 3. 定义WebService服务 通过Axis提供的注解来定义WebService服务。 ```java @AxisService public class HelloWebService { @WebMethod public String sayHello(String name) { return "Hello, " + name + "!"; } } ``` 注意:要确保WebService服务类被Spring Boot扫描到,可以通过在配置类上添加`@ComponentScan`注解来实现。 4. 配置wsdd文件 在src/main/resources目录下创建wsdd文件夹,并创建AxisServlet.wsdd文件,配置如下: ```xml <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="HelloWebService" provider="java:RPC"> <parameter name="className" value="com.example.demo.webservice.HelloWebService"/> <parameter name="allowedMethods" value="*"/> </service> </deployment> ``` 这样就配置好了WebService服务端,可以启动Spring Boot应用并访问WebService服务了。例如,在浏览器中访问`http://localhost:8080/services/HelloWebService?wsdl`来查看WebService服务的WSDL描述文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值