我使用cxf从wadl文件生成了java类。定义了3个资源,因此创建了3个具有@PATH注释的服务类。现在我想将它们发布到同一个网址,但我不知道如何实现这一目标。 以下是课程和wadl的片段。最后一部分显示了beans.xml - 此时这是我知道如何发布端点的唯一方法。是否有其他方式,我如何将这3个类发布到基本网址" /"然后它们应匹配与注释相关的路径。可能是所有人的包装课,但我不确定?
类
@Path("status")
public class Status {
...
@Path("status/{id}")
public class StatusId {
...
@Path("counters")
public class Counters{
...
WADL
<resources base="http:localhost:8080/rest">
<resource path="status/{id}" id="status">
<method name="GET" id="getStatusById">
...
<resource path="status" id="status">
<method name="GET" id="getStatusByQueryParam">
...
</resource>
<resource path="counters" id="counters">
<method name="PUT" id="putCounters">
...
的beans.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:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<!-- do not use import statements if CXFServlet init parameters link to this beans.xml -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxrs:server id="statusService" address="/">
<jaxrs:serviceBeans>
<ref bean="status" />
</jaxrs:serviceBeans>
</jaxrs:server>
<!-- causes error
<jaxrs:server id="statusServiceId" address="/">
<jaxrs:serviceBeans>
<ref bean="statusId" />
</jaxrs:serviceBeans>
</jaxrs:server>
<jaxrs:server id="counterServiceId" address="/">
<jaxrs:serviceBeans>
<ref bean="counters" />
</jaxrs:serviceBeans>
</jaxrs:server>
-->
<bean id="status" class="package.Status"/>
<bean id="statusId" class="package.StatusId"/>
<bean id="counters" class="package.Counters"/>
</beans>
答案 0 :(得分:0)
用于确定多个端点 beans.xml 应该看起来像下面的
<jaxrs:server id="statusService" address="/">
<jaxrs:serviceBeans>
<ref bean="status" />
<ref bean="statusId" />
<ref bean="counters" />
</jaxrs:serviceBeans>
</jaxrs:server>