5
作爲this question的後續工作,我仍然對如何正確使用CXF-RS組件感到困惑。爲什麼我們在使用CXF-RS組件時使用<cxf:rsServer>而不是普通的<jaxrs:server>?
我很困惑,爲什麼我們需要確定CXF-RS端點<cxf:rsServer>
標籤(或者甚至有這樣一個概念?),我可以使用<jaxrs:server>
標籤完美的罰款。
這裏有兩個駱駝和CXF我的XML配置:
<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:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="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.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<jaxrs:server id="userService" address="/users">
<jaxrs:serviceBeans>
<bean class="com.example.UserServiceNoop" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
</jaxrs:providers>
</jaxrs:server>
<bean id="user" class="org.apache.camel.component.direct.DirectComponent" />
<camel:camelContext id="someCamelContext">
<camel:route id="userServiceRoute">
<camel:from uri="cxfrs:bean:userService" />
<camel:routingSlip>
<camel:simple>user:${header.operationName}</camel:simple>
</camel:routingSlip>
</camel:route>
<camel:route id="userServiceRetrieveUser">
<from uri="user:retrieveUser" />
<!-- Assume this is going to a useful Processor -->
</camel:route>
</camel:camelContext>
</beans>
UserService.java:
package com.example;
/* a bunch of imports... */
public interface UserService {
@GET
@Path(value="/{user.id}")
@Produces({MediaType.APPLICATION_JSON})
public User retrieveUser(
@PathParam("user.id") Integer id
);
}
UserServiceNoop.java
package com.example;
/* a bunch of imports ... */
public class UserServiceNoop implements UserService
{
@Override
public User retrieveUser(Integer id) {
throw new RuntimeException();
}
}
在這個例子中,我不是使用任何<cxf:rsServer>
標籤,但它工作正常。我知道它通過CXF-RS組件,因爲當我運行應用程序時,它不會拋出任何RuntimeExceptions,這是使用CXF-RS時的預期行爲(服務類中的方法實現將不會被調用)。
我錯過了什麼不使用這個標籤?
謝謝!