我使用RESTful
在Web应用程序中开发了一个简单的Apache CXF
服务,并且工作正常。
我可以通过“http://localhost:8080/SpringRestProjectJava/api/books/1234
”访问它,我也会得到正确的JSON
响应。
我的理解是from this link WADL
将自动生成。
这是对的吗?如果是,我如何查看WADL
此服务。
这是我的web.xml
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/CustomSpringConfig.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>simplerest</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>org.gsdev.ws.bookservice.BookResource</param-value>
</init-param>
<init-param>
<param-name>jaxrs.providers</param-name>
<param-value>org.gsdev.ws.bookservice.provider.XstreamJsonProvider</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>simplerest</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
这是我的BookResource.java
@Path( "books/{isbn}" )
public class BookResource {
@GET
@Produces ( "application/json" )
public Book getDetails( @PathParam("isbn") String isbn){
if( isbn.equals( "1234" )){
Book book = new Book();
book.setIsbn(isbn);
book.setTitle("Learning web services by Garry");
return book;
}
return null;
}
}
答案 0 :(得分:1)
最后,继续尝试后,我能够让它发挥作用。我认为这是由于CXFNonSpringJaxrsServlet
。我做了以下更改,我能够访问自动生成的WADL
。
对web.xml
<servlet>
<servlet-name>simplerest</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>simplerest</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
在cxf-servlet.xml
WEB-INF
<jaxrs:server id="bookService" address="/bookservice">
<jaxrs:serviceBeans>
<ref bean="bs"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean='jsonProvider' />
</jaxrs:providers>
</jaxrs:server>
<bean id="bs" class="org.gsdev.ws.bookservice.BookResource"/>
<bean id="jsonProvider" class="org.gsdev.ws.bookservice.provider.XstreamJsonProvider"/>
答案 1 :(得分:-1)