gpt4 book ai didi

web-services - 使用 WSSpringServlet 的带有 SOAP Web 服务的 Spring MVC 应用程序

转载 作者:行者123 更新时间:2023-12-04 04:43:44 24 4
gpt4 key购买 nike

我创建了一个简单的 Spring MVC Web 应用程序,并尝试使用 JAX-WS commons RI 将服务公开为基于 SOAP 的 JAX-WS 服务。实现。

在 Tomcat 7 上部署我的应用程序后,当我尝试访问我的 Web 服务时,我收到一条消息 404 Not Found: Invalid Request。以下是我的配置,请帮助解决此问题。

网页.xml

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes SOAP Web Service requests -->
<servlet>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>

<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

WEB-INF/spring/appServlet/servlet-context.xml

    <beans:bean id="customerService" class="com.home.service.CustomerService" />

<!-- Web Service definition -->
<beans:bean id="customerWS" class="com.home.ws.CustomerWS">
<beans:property name="customerService" ref="customerService" />
</beans:bean>

<wss:binding url="/ws/CustomerServ">
<wss:service>
<ws:service bean="#customerWS" />
</wss:service>
</wss:binding>

客户WS.java

@WebService
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL)
public class CustomerWS {

private CustomerService customerService;

@WebMethod
public Customer read(long id) {
return customerService.read(id);
}

public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}
}

客户服务.java

@Service
public class CustomerService {
public Customer read(long id) {
Customer cust = null;
System.out.println("CustomerService.read invoked");

return cust;
}
}

pom.xml - 包含 jaxws-spring 的依赖

    <dependency>
<groupId>org.jvnet.jax-ws-commons.spring</groupId>
<artifactId>jaxws-spring</artifactId>
<version>1.9</version>
</dependency>

构建或部署应用程序时没有错误。当我访问 URL 时,我仍然看不到服务器日志文件中的错误。但是,浏览器显示消息 - 404 未找到:无效请求

我正在尝试的 URL 是 - http://localhost:8080/crrs/ws/CustomerServ?wsdl
如果我访问我的 HomeController,它工作正常。主页已按预期加载。

感谢任何帮助。提前致谢。

最佳答案

我正在尝试做同样的事情。我的代码几乎相同,我只是使用@Name 和@Inject 而不是@Service。

刚刚添加 extends SpringBeanAutowiringSupport@WebService类,它的工作

关于web-services - 使用 WSSpringServlet 的带有 SOAP Web 服务的 Spring MVC 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18513333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com