Sorry not good at English.
I use cxf for the first time.

Refer to the various sample, I tried to create a simple REST web service
with apache cxf.

I succeed when @Produces tag set "application/xml".
but failed when @Produces tag set "application/json" with [No message body
writer has been found for response class Document] message.

result is below
-------------------------------------------------------------------------------------
[when @Produces("application/xml")]
<document>
    <name>aaa</name>
</document>

[when @Produces("application/json")]
No message body writer has been found for response class Document.
-------------------------------------------------------------------------------------

my code is below.
-------------------------------------------------------------------------------------
[Resource Interface class]
@Path("/document")
public interface DocumentResource {
        
        @GET
        @Path("/name/{name}")
        @Produces("application/json")
        Document getDocument(@PathParam("name") String name);

}

[Implement class]
@Component
public class DocumentResourceImpl implements DocumentResource {

        public Document getDocument(String name) {
                Document doc = new Document();
                doc.setName(name);
                return doc;
        }

}

[Document class]
@XmlRootElement
public class Document {
        private String name;
        
        public String getName() {
                return name;
        }
        public void setName(String name) {
                this.name = name;
        }
}

[applicationContext.xml]
<beans ...>

  <import resource="classpath:META-INF/cxf/cxf.xml" />
    
  <context:component-scan base-package="jp.sample.jaxrs" />
  
  <jaxrs:server id="documentResource" address="/">
    <jaxrs:serviceBeans>
        <ref bean="documentResourceImpl" />
    </jaxrs:serviceBeans>
  </jaxrs:server>

</beans>

[pom.xml]
<project ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>jp.example.webapp</groupId>
  <artifactId>jax-rs</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>jax-rs Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
      <dependency>
          <groupId>org.apache.cxf</groupId>
          <artifactId>cxf-rt-frontend-jaxrs</artifactId>
          <version>2.6.2</version>
          <type>jar</type>
          <scope>compile</scope>
      </dependency>
      <dependency>
          <groupId>org.apache.cxf</groupId>
          <artifactId>cxf-bundle-jaxrs</artifactId>
          <version>2.6.2</version>
          <type>jar</type>
          <scope>compile</scope>
      </dependency>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>3.0.7.RELEASE</version>
          <type>jar</type>
          <scope>compile</scope>
      </dependency>
  </dependencies>
  <build>
    <finalName>jax-rs</finalName>
  </build>
</project>
-------------------------------------------------------------------------------------

What is the cause of this problem(code? configuration? library?)

Thank you.



--
View this message in context: 
http://cxf.547215.n5.nabble.com/No-message-body-writer-has-been-found-for-response-class-is-returned-only-application-json-tp5713730.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to