spring+cxf整合,服务器端访问wsdl文件报错

薄暮凉年 发布于 2015/06/15 14:51
阅读 1K+
收藏 0
<!--这个是用maven集成的 这个是依赖的jar-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.liyi.lianxi</groupId>
  <artifactId>hellocxf</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>hellocxf Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
        <pro.outerDirectory>src/main/webapp</pro.outerDirectory> 
    </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
    <!-- cxf -->
    <dependency>
        	<groupId>commons-pool</groupId>
        	<artifactId>commons-pool</artifactId>
        	<version>20030825.183949</version>
        </dependency>
        
        <dependency>
		   <groupId>org.apache.cxf</groupId>
		   <artifactId>cxf-api</artifactId>
		   <version>2.5.0</version>
	  </dependency>
	  <dependency>
		   <groupId>org.apache.cxf</groupId>
		   <artifactId>cxf-rt-frontend-jaxws</artifactId>
		   <version>2.5.0</version>
	  </dependency>
	  <dependency>
		   <groupId>org.apache.cxf</groupId>
		   <artifactId>cxf-rt-bindings-soap</artifactId>
		   <version>2.5.0</version>
	  </dependency>
	  <dependency>
		   <groupId>org.apache.cxf</groupId>
		   <artifactId>cxf-rt-transports-http</artifactId>
		   <version>2.5.0</version>
	  </dependency>
	  <dependency>
		   <groupId>org.apache.cxf</groupId>
		   <artifactId>cxf-rt-ws-security</artifactId>
		   <version>2.5.0</version>
	  </dependency>
    
  </dependencies>
  
  <build>
   <plugins>    
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
                  <encoding>UTF-8</encoding>
                  <compilerArguments>
                   <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
                 </compilerArguments>
              </configuration>
            </plugin>

    </plugins>
    <finalName>hellocxf</finalName>
  </build>
</project>

//这个是web.xml
<!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>
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath*:applicationContext.xml</param-value>  
    </context-param>  
    <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener>  
      <servlet> 
        <servlet-name>CXFServlet</servlet-name> 
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 
        <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
        <servlet-name>CXFServlet</servlet-name>  
        <url-pattern>/webservice/*</url-pattern> 
    </servlet-mapping>
</web-app>

//这个是spring的核心文件
<?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:p="http://www.springframework.org/schema/p"  
        xmlns:jaxws="http://cxf.apache.org/jaxws"  
            xmlns:cxf="http://cxf.apache.org/core"  
        xsi:schemaLocation="http://www.springframework.org/schema/beans   
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
            http://cxf.apache.org/jaxws   
            http://cxf.apache.org/schemas/jaxws.xsd">  
       
        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  

<!--         <bean id="helloCxfImpl" class="com.liyi.service.impl.HelloCxfImpl"/> -->
        <bean id="helloCxfImpl" class="com.liyi.service.impl.HelloCxfImpl"/> 
        <jaxws:endpoint id="helloCxf" implementor="#helloCxfImpl" address="/HelloCxf" /> 

</beans>   

//这个是接口
package com.liyi.service;

import javax.jws.WebService;

@WebService
public interface HelloCxf {
    public String sayHello(String name);
}

//这个是实现类
package com.liyi.service.impl;

import javax.jws.WebService;

import com.liyi.service.HelloCxf;
@WebService(endpointInterface="com.liyi.service.HelloCxf")
public class HelloCxfImpl implements HelloCxf{

    public String sayHello(String name) {
        // TODO Auto-generated method stub
        return "sayHello to "+ name;
    }

}

启动项目没有报错,而且访问http://localhost:8080/hellocxf可以跳到index.jsp.
但是访问http://localhost:8080/hellocxf/webservice/HelloCxf?wsdl就报错
报错如下:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined
	org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
	org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1094)
	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:276)
	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
	org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)
	org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:60)
	org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:64)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	java.lang.Thread.run(Thread.java:662)

求指教!



加载中
0
开源中国首席逆风
开源中国首席逆风
没有把cxf组件,注入到springon容器啊
0
开源中国首席逆风
开源中国首席逆风
没有注入到spring容器啊
薄暮凉年
薄暮凉年
什么意思?怎么注入到spring 容器里面?那个import不是吗?
0
开源中国首席逆风
开源中国首席逆风
  1.        <import resource="classpath:META-INF/cxf/cxf.xml" />  
  2. <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
  3. <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  
  4.       <!-- hello -->  
  5. <bean id="aegisBean"    
  6.        class="org.apache.cxf.aegis.databinding.AegisDatabinding" />   
  7.            
  8.    <bean id="jaxws-and-aegis-service-factory"    
  9.        class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">     
  10.        <property name="dataBinding" ref="aegisBean" />     
  11.    </bean>    
  12.   
  13.   <!-- hello -->  
  14.  <jaxws:server id="hello" serviceClass="com.framework.webservice.Hello" address="/Hello">  
  15.         <jaxws:serviceBean>  
  16.             <bean class="com.framework.webservice.HelloImpl">  
  17.             </bean>  
  18.         </jaxws:serviceBean>  
  19.  </jaxws:server>  
薄暮凉年
薄暮凉年
因为jar包的原因,不支持,所以就报错了,现已解决。谢谢
0
zigzagroad
zigzagroad
没有把你所开发的提供Web服务的程序 配置到Spring中。
薄暮凉年
薄暮凉年
因为jar包的原因,不支持,所以就报错了,现已解决
返回顶部
顶部