2 u010717479 u010717479 于 2016.01.15 22:52 提问

关于cxf resutful 中出现No resource classes found的问题

用cxf开发restful服务,出现以下问题,希望大家能给予帮助,在此先谢过。

 Caused by: org.apache.cxf.service.factory.ServiceConstructionException
    at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:219)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1706)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1645)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 62 more
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: No resource classes found
    at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJAXRSFactoryBean.java:317)
    at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:159)
    ... 69 more

7个回答

CSDNXIAOD
CSDNXIAOD   2016.01.15 22:54

CXF中,出现 No services have been found.
Android出错问题:AndroidManifest.xml:2: error: No resource identifier found for attribute 'installLocatio
error: No resource identifier found for attribute 问题
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

u010717479
u010717479   2016.01.15 22:54

我的配置如下:
(1)、web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
         id="WebApp_ID" version="3.1">
  <display-name>Archetype Created Web Application</display-name>
  <!-- B:配置中文编码问题的过滤器 -->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- E:配置中文编码问题的过滤器 -->

    <!-- B:配置Spring配置文件的名称和位置 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:cxf-server.xml
        </param-value>
    </context-param>
    <!-- E:配置Spring配置文件的名称和位置 -->

    <!-- B:启动IOC容器的ServletContextListener -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- E:启动IOC容器的ServletContextListener -->

    <!-- B:CXF servlet -->
    <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>
      <!-- 匹配下/services/*的所有请求 -->
      <url-pattern>/services/*</url-pattern>
   </servlet-mapping>
   <!-- E:CXF servlet -->
</web-app>

u010717479
u010717479   2016.01.15 22:55

(2)、pom.xml

 <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.github.mervyn</groupId>
    <artifactId>java-learn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <groupId>org.github.mervyn.webServices_CXF_springRestful</groupId>
  <artifactId>java-learn-webServices_CXF_springRestful</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <packaging>war</packaging>
  <name>java-learn-webServices_CXF_springRestful Maven Webapp</name>
  <url>http://maven.apache.org</url>

   <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>4.2.3.RELEASE</spring.version>
    <cxf.version>3.1.4</cxf.version>
    <jackson.version>1.9.13</jackson.version>
    <jsr311.version>1.1.1</jsr311.version>
    <!-- jetty context path -->
    <jetty.contextPath>java-learn-webServices_CXF_springRestful</jetty.contextPath>
  </properties>

  <dependencies>
   <!-- B:spring依赖 -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>   
    <!-- E:spring依赖 -->

    <!-- B:cxf依赖 -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-extension-providers</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <!-- E:cxf依赖 -->

    <!-- B:javax.ws.rs -->
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>jsr311-api</artifactId>
        <version>${jsr311.version}</version>
    </dependency>
    <!-- E:javax.ws.rs -->


    <!-- B:jackson -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-jaxrs</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <!-- E:jackson -->

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>java-learn-webServices_CXF_springRestful</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <encoding>utf8</encoding>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <version>9.0.0.v20130308</version>
            <configuration>

                <webApp>
                  <contextPath>/${jetty.contextPath}</contextPath>
                </webApp>
                <!-- 热部署时间 -->
                <scanIntervalSeconds>5</scanIntervalSeconds>
                <webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>
            </configuration>
        </plugin>
    </plugins>
  </build>

</project>

u010717479
u010717479   2016.01.15 22:55

(3)、HelloWS接口

 package org.github.mervyn.webServices_CXF_springRestful;


import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


public interface IHelloWS {

    @GET
    @Path("/HelloWS/{id}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({MediaType.APPLICATION_JSON,"text/html; charset=UTF-8"})
    String getUserById(@PathParam("id")int id);
}
u010717479
u010717479   2016.01.15 22:56

(4)、HelloWSImpl

 package org.github.mervyn.webServices_CXF_springRestful;


import java.io.IOException;
import java.io.StringWriter;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;


public class HelloWSImpl implements IHelloWS {

    @Override
    /*@GET
    @Path("/HelloWS/{id}")
    //@Consumes(MediaType.APPLICATION_JSON)
    @Produces({MediaType.APPLICATION_JSON,"text/html; charset=UTF-8"})*/
    public String getUserById(@PathParam("id")int id){
        System.out.println("id为: " + id);
        User user = new User();
        user.setId(id);
        user.setName("mervyn");
         ObjectMapper mapper = new ObjectMapper();  
         StringWriter sw = new StringWriter(); 
         JsonGenerator gen = null;
         try {
             gen = new JsonFactory().createJsonGenerator(sw);
             mapper.writeValue(gen, user);
             gen.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String json = sw.toString();
        return json;
    }

}
u010717479
u010717479   2016.01.15 22:56

(5)cxf-server.xml

 <?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:core="http://cxf.apache.org/core"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xsi:schemaLocation="http://cxf.apache.org/core http://cxf.apache.org/schemas/core.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://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

    <import resource="classpath*:META-INF/cxf/cxf.xml" />
    <import resource="classpath*:META-INF/cxf/cxf-servlet.xml" /> 

    <bean id="helloWSImpl" class="org.github.mervyn.webServices_CXF_springRestful.HelloWSImpl" />

    <jaxrs:server id="iHelloWS" address="/">
        <jaxrs:serviceBeans>
            <ref bean="helloWSImpl"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>



</beans>
u010717479
u010717479   2016.01.16 15:08

问题已解决。是因为自己粗心。cxf实现restful风格的web services 接口上写上注解,同时也要在接口的实现类中添加上相应的注解。图片说明

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
<br />java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist<br />解决办法:<br />META-INF目录下面新建一个xfire文件夹,把services.xml文件放到这个文件夹里,再将整个META-INF拷贝到WEB-INF中<br />clean一下工程重新加载后启动服务就可以了
Apache CXF 的REST 方式发布WebService实现,Android手机后台服务的开发
最近项目中采用Apache CXF 的REST 方式发布WebService实现,Android手机后台服务的开发,以下以简单是实例实现。 在项目中采用Android+REST WebService服务方式开发的手机平台很少采用 soap协议这种方式,主要soap协议解析问题,增加了代码量。  采用RESTFull 方式开发WebService的好处,相对SOAP协议的WebService来说,
Maven使用tomcat7运行报错:Unable to determine URL for WEB-INF/classes
在pom.xml中的配置如下: maven_demo_web org.apache.tomcat.maven tomcat7-maven-plugin 2.0-beta-1
cxf和spring集成注入值为NULL问题
用cxf+spring开发web service程序很简单,不过有一些集成问题要注意。  1、关于bean的声明  要发布或者要调用的web service接口,需要用@WebService注解声明。不过要注意的是,@WebService注解不会把类声明为spring的bean  可以声明为bean的方式有以下4个:        @Component  写
maven整合CXF WebService+Spring @Resource无法注入问题解决方法
笔者是一个出道不长的小码农.工作中需要用的maven 结合jetty容器进行开发的前提背景下 废话不多说直接上代码 更改前的web.xml     cxf                 contextConfigLocation         classpath:beans.xml                 contextConfigLocati
Maven介绍与应用
Maven介绍
NameNotFoundException:原来是Tomcat7的一个bug
最近,我电脑上的Tom猫由于项目原因,换成了7.0的版本,但是,我发现经常会出现错误,并且在给别人弄得时候也是出现了这样子的错误。错误是这样的:javax.naming.NameNotFoundException: Resource /WEB-INF/classes not found 刚刚实在郁闷,一切配置和项目都是正常的,为什么会出现这样的错误的呢?我真是按耐不住了就上网查了查,竟然是Tom
笔记-总结
1、sendKeys传参出现错误: 修改为: driver.findElement(By.id(&amp;amp;quot;kw&amp;amp;quot;)).sendKeys(new String[] { &amp;amp;quot;selenium java&amp;amp;quot; }); 2、WebDriver driver = new ChromeDriver(); 需要配置环境变量PATH:将谷歌浏览器.exe所在文件夹放在PATH里面;
在 Spring 配置文件中导入 CXF 提供 Schema、XML 详情
3 . 在 Spring 配置文件中导入 CXF 提供 Schema、XML(cxf.jar 包里提供) * Schema 文件 <beans xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://c
CXF之<import resource="classpath:META-INF/cxf/cxf.xml" />找不到文件的问题
研究了好几天的CXF webservice ;在进行spring整合的时候;配置beans.xml中需要引用相关的xml文件; 网上搜索了好多关于cxf整合spring的文章,发现并没有提到过引入xml文件的过多的解释,都是稍微一点就带过。 然后在我进行学习的时候就会发现各种找不到文件的错误; 很是蛋疼  于是的于是,终于让我找到了问题所在; 原因就是在CXF的3.0版本之前是需要引进三个