Java apachecxf和tomcat

Java apachecxf和tomcat,java,tomcat,cxf,Java,Tomcat,Cxf,我对apachecxf和tomcat相当陌生。我正在尝试构建一个简单的web服务并将其部署到tomcat上。下面是我的web.xml 但是,当我尝试使用浏览器访问“服务”文件夹时,它显示未找到任何服务。我尝试创建JavaWeb服务客户端,但它也找不到服务。这有什么不对吗 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" x

我对apachecxf和tomcat相当陌生。我正在尝试构建一个简单的web服务并将其部署到tomcat上。下面是我的web.xml 但是,当我尝试使用浏览器访问“服务”文件夹时,它显示未找到任何服务。我尝试创建JavaWeb服务客户端,但它也找不到服务。这有什么不对吗

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <display-name>Sample web service provider</display-name>
    <listener>
        <!-- For Metro, use this listener-class instead: 
             com.sun.xml.ws.transport.http.servlet.WSServletContextListener -->
        <listener-class>
              org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <!-- Remove below context-param element if using Metro -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
              classpath:META-INF/cxf/cxf.xml
        </param-value>
    </context-param>
    <servlet>
        <servlet-name>WebServicePort</servlet-name>
        <!-- For Metro, use this servlet-class instead: 
             com.sun.xml.ws.transport.http.servlet.WSServlet  -->
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>WebServicePort</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
</web-app>

示例web服务提供者
org.springframework.web.context.ContextLoaderListener
上下文配置位置
类路径:META-INF/cxf/cxf.xml
WebServicePort
org.apache.cxf.transport.servlet.CXFServlet
1.
WebServicePort
/服务/*
60

这意味着您的应用程序中没有公开任何服务。您的
web.xml
似乎是正确的,但我刚刚错过了一件事,您的Spring配置。在
web.xml
中添加Spring配置位置,例如:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
您的
CandidateImpl
类应该有注释。例如:

<bean id="candidateImpl" class="some.pckg.CandidateImpl"/>

<jaxws:endpoint id="candidateEndpoint"
                implementor="#candidateImpl"
                address="/Candidate"
        />
@WebService(targetNamespace = "http://something.com/ws/candidate",
        portName = "CandidateService",
        serviceName = "Candidate",
        endpointInterface = "some.pckg.types.CandidateService",
        wsdlLocation = "WEB-INF/wsdl/CandidateService.wsdl")
public class CandidateImpl implements CandidateService {
     //Implementation of all methods from CandidateService.
}
如果您已经正确地完成了所有操作,您应该看到在以下目录下有一项服务可用:

http(s)://whateverhost.com:<somePort>/SomeContextPath/services
http://whateverhost.com:/SomeContextPath/services
您应该能够获得如下所示的WSDL文件:

http(s)://whateverhost.com:<somePort>/SomeContextPath/services/Candidate?wsdl
http://whateverhost.com:/SomeContextPath/services/Candidate?wsdl
另请参见:


您需要设置spring配置文件的位置以使其正常工作。您可以按如下方式进行设置

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>

上下文配置位置
WEB-INF/applicationContext.xml

您需要在web.xml中配置servlet。下面是一个例子

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
       PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
       "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

   <servlet>
       <servlet-name>CXFServlet</servlet-name>
       <display-name>CXF Servlet</display-name>
       <servlet-class>
           org.apache.cxf.transport.servlet.CXFServlet
       </servlet-class>
       <init-param>
           <param-name>config-location</param-name>
           <param-value>/WEB-INF/spring-ws-servlet.xml</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
       <servlet-name>CXFServlet</servlet-name>
       <url-pattern>/services/*</url-pattern>
   </servlet-mapping>

</web-app>

CXF服务器
cxfservlet
org.apache.cxf.transport.servlet.CXFServlet
配置位置
/WEB-INF/spring-ws-servlet.xml
1.
CXF服务器
/服务/*
现在需要在WEB-INF文件夹下定义一个名为spring-ws-servlet.xml的文件。下面是spring-ws-servlet.xml的内容示例,其中包含web服务的实际配置。当然,这取决于您的逻辑:

<?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:context="http://www.springframework.org/schema/context"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd
       http://cxf.apache.org/jaxws
       http://cxf.apache.org/schemas/jaxws.xsd">

   <context:component-scan base-package="com.sample.service"/>

   <!-- JAX-WS Service Endpoint -->
   <bean id="personImpl" class="com.sample.service.impl.PersonServiceImpl"/>

   <jaxws:endpoint id="personEndpoint"
                   implementor="#personImpl"
                   address="/person">
       <jaxws:properties>
           <entry key="schema-validation-enabled" value="true"/>
       </jaxws:properties>
   </jaxws:endpoint>
   <!-- JAX-WS Service Endpoint End-->
</beans>

有了它,您可以在下访问web服务

这是从这篇文章中摘取的。这是一篇关于使用IntelliJ Idea和Spring创建Cxf服务的教程


虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,只有链接的答案可能会无效。好的,我已经用丢失的信息更新了答案。希望能有帮助。