cxf 3.2+webservice+spring 4.2发布Rest WebService
2018-03-19 10:32
441 查看
1.接口interface:
@WebService(serviceName="ShowCaseService", endpointInterface = "com.xxx.demo.service.ShowCaseService")
@Path("/showCases")
@Api(value = "/showCases")
public interface ShowCaseService
{
//http://localhost:8080/pis-web/services/api/showCases
@GET
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(
value = "查询所有ShowCase记录",
notes = "使用Mabatis进行数据库查询",
response = ShowCase.class
)
List<ShowCase> getAll();
}
实现类impl:
@Service("showCaseWebService")
public class ShowCaseWebServiceImpl implements ShowCaseService
{
@Autowired
private ShowCaseDao showCaseDao ;
@Override
public List<ShowCase> getAll()
{
return showCaseDao .getAll();
}
}
2.web.xml配置文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
<!-- Configuration Locations for Monolith Mode Begin-->
classpath*:/applicationContext.xml
/WEB-INF/applicationContext*.xml
/WEB-INF/cxf-servlet.xml
/WEB-INF/security.xml
</param-value>
</context-param>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
3.cxf.xml配置文件:
<jaxws:endpoint id="showCaseService" implementor="#showCaseWebService" address="/ShowCaseService"/>
<jaxrs:server address="/api">
<jaxrs:serviceBeans>
<!-- 引入实现类--!>
<ref bean="showCaseWebService"/>
</jaxrs:serviceBeans>
</jaxrs:server>
发布失败原因总结:
1.发布失败原因测试类的注入报错导致项目启动报错。
2.services接口中的方法的参数不能为接口类型,如HttpServletResponse,否则报错:
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
javax.servlet.http.HttpServletResponse是接口, 而 JAXB 无法处理接口。
this problem is related to the following location:
at javax.servlet.http.HttpServletResponse
at private javax.servlet.http.HttpServletResponse com.purang.pis.asset.service.jaxws_asm.ExportData.arg1
at com.purang.pis.asset.service.jaxws_asm.ExportData;
services中的方法;
public String exportData(List<Deal> list, HttpServletResponse response,String assettype,String[] headers_title);
可以找到错误的地方在ExportData方法的参数;
3.http://localhost:8080/services/访问发布的服务地址
4.接口中需要加入的注解:
@WebService(serviceName="ShowCaseService", endpointInterface = "com.xxx.demo.service.ShowCaseService")
@Path("/showCases")
@Api(value = "/showCases")
public interface ShowCaseService
{
//http://localhost:8080/pis-web/services/api/showCases
@GET
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(
value = "查询所有ShowCase记录",
notes = "使用Mabatis进行数据库查询",
response = ShowCase.class
)
List<ShowCase> getAll();
}
实现类impl:
@Service("showCaseWebService")
public class ShowCaseWebServiceImpl implements ShowCaseService
{
@Autowired
private ShowCaseDao showCaseDao ;
@Override
public List<ShowCase> getAll()
{
return showCaseDao .getAll();
}
}
2.web.xml配置文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
<!-- Configuration Locations for Monolith Mode Begin-->
classpath*:/applicationContext.xml
/WEB-INF/applicationContext*.xml
/WEB-INF/cxf-servlet.xml
/WEB-INF/security.xml
</param-value>
</context-param>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
3.cxf.xml配置文件:
<jaxws:endpoint id="showCaseService" implementor="#showCaseWebService" address="/ShowCaseService"/>
<jaxrs:server address="/api">
<jaxrs:serviceBeans>
<!-- 引入实现类--!>
<ref bean="showCaseWebService"/>
</jaxrs:serviceBeans>
</jaxrs:server>
发布失败原因总结:
1.发布失败原因测试类的注入报错导致项目启动报错。
2.services接口中的方法的参数不能为接口类型,如HttpServletResponse,否则报错:
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
javax.servlet.http.HttpServletResponse是接口, 而 JAXB 无法处理接口。
this problem is related to the following location:
at javax.servlet.http.HttpServletResponse
at private javax.servlet.http.HttpServletResponse com.purang.pis.asset.service.jaxws_asm.ExportData.arg1
at com.purang.pis.asset.service.jaxws_asm.ExportData;
services中的方法;
public String exportData(List<Deal> list, HttpServletResponse response,String assettype,String[] headers_title);
可以找到错误的地方在ExportData方法的参数;
3.http://localhost:8080/services/访问发布的服务地址
4.接口中需要加入的注解:
@GET @Path("/getAll/") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})否则无法返回结果
相关文章推荐
- Spring 集成CXF框架发布Webservice服务 和 使用jdk生成Webservice clinet
- webservice--CXF+Spring整合发布REST的服务
- Web应用中使用CXF不基于Spring的WebService发布
- webservice--cxf和spring结合,发布restFull风格的服务
- 8、CXF与Spring整合发布http rest 风格的WebService服务
- cxf集成到spring中发布restful webservice
- spring整合cxf方式发布的rest webservice,调用接口
- Spring整合CXF 发布webservice接口服务器(普通及REST)和客户端,WSDL简单解析
- Axis Web Service开发之旅 (三) --将Spring的装配JavaBean发布成WebService
- CXF+Spring+REST发布webservice服务
- Web应用中使用CXF不基于Spring的WebService发布
- maven 项目 cxf+spring 发布rest风格webservice
- Spring整合CXF配置WebService服务发布
- Eclipse安装CXF插件开发java web service 集成Spring
- Restful(二)Spring整合CXF,发布RSETful 风格WebService
- 使用CXF发布和调用webService(不使用Spring)
- spring集成webservice框架cxf,访问报错service not found
- 在 Web 容器中使用 Spring + CXF 发布 WS(一)
- WSDL/WebService/SOAP/REST/AXIS/CXF 开放式服务
- 使用CXF与Spring集成实现RESTFul WebService