我是cxf和camel的新手,在尝试使用JacksonJsonProvider时遇到了一些问题。
我正在尝试定义一个消耗json对象的cxf服务端点,并将请求发送到camel路由。骆驼路线对我的问题并不重要。
在我的blueprint.xml文件中,我为JacksonJsonProvider定义了一个bean:
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
当我尝试在karaf中安装我的功能时,我收到以下错误:
BlueprintContainerImpl | ?
? | 21 - org.apache.aries.blueprint.core - 1.4.2 |无法开始 捆绑测试的蓝图容器-mgw-api org.osgi.service.blueprint.container.ComponentDefinitionException: 无法加载类org.codehaus.jackson.jaxrs.JacksonJsonProvider 来自配方BeanRecipe [name =&#39; jsonProvider&#39;]
我已经将正确的依赖项添加到了我的pom.xml
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.13</version>
</dependency>
我必须在这里找到一些简单的东西,但我现在花了很多时间才弄明白而且我无处可去。 有人知道我在这里做错了吗?
我在这里提供了我的代码。
服务界面:
@Path("/auth/")
public interface AuthService {
@POST
@Path("/login")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
Response login(LoginRequest loginRequest);
@GET
@Path("/person/get/{id}/")
@Produces("application/xml")
Response getPerson(@PathParam("id") String id);
@DELETE
@Path("/person/delete/{id}")
void deletePerson(@PathParam("id") String id);
}
请求型号:
@XmlRootElement(name="Login")
public class LoginRequest {
private String username;
private String password;
private int loginType;
public LoginRequest(String username, String password) {
this.username = username;
this.password = password;
this.loginType = 1;
}
public LoginRequest() {
}
}
Blueprint.xml
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<cm:property-placeholder persistent-id="test.mgw.cxf.receive" update-strategy="reload">
<cm:default-properties>
<cm:property name="CXFserver" value="http://localhost:8989/"/>
<cm:property name="service" value="rest" />
</cm:default-properties>
</cm:property-placeholder>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
<cxf:rsServer id="rsServer" address="${CXFserver}${service}"
serviceClass="test.mgw.api.AuthService"
loggingFeatureEnabled="true" loggingSizeLimit="20">
<cxf:providers>
<ref component-id="jsonProvider"/>
</cxf:providers>
</cxf:rsServer>
</blueprint>
答案 0 :(得分:0)
您应该将代码的蓝图更改为jaxrs like this:
<jaxrs:server id="endpoint1">
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
</jaxrs:providers>
</jaxrs:server>