【发布时间】:2017-10-23 12:27:41
【问题描述】:
我创建了 maven 项目来向 jboss fuse 公开 REST Web 服务:
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javainuse</groupId>
<artifactId>apache-camel-jaxrs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.12.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.4.0</version>
</plugin>
</plugins>
</build>
applicationContext.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="restService" address="http://localhost:9000/employeeservice">
<jaxrs:serviceBeans>
<ref bean="employeeService" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="employeeService" class="com.javainuse.beans.EmployeeServiceResource" />
EmployeeServiceResource.java
package com.javainuse.beans;
@Path("/")
public class EmployeeServiceResource {
public EmployeeServiceResource() {
}
@GET
@Path("/employees/{name}/")
public String getCustomer(@PathParam("name") String name) {
return "Welcome " + name;
}
}
JBoss Fuse 命令:
JBossFuse:karaf@root>安装 mvn:com.javainuse/apache-camel-jaxrs/0.0.1-SNAPSHOT
捆绑 ID:333
JBossFuse:karaf@root> START 333 -> 给我这个例外: org.springframework.beans.factory.BeanCreationException:创建名为“restService”的bean时出错:bean初始化失败;嵌套异常是 java.lang.NullPointerException
我正在使用 JBoss Fuse 6.3 和 java 1.8
【问题讨论】:
-
发布完整的堆栈跟踪
-
并修复您的版本。在 JBoss Fuse 6.3.0 上有 Camel 2.17。在你的 POM 中使用这个版本。我还将编译器插件更新为 3.5.1,强制 Java8 作为源和目标,并将 maven-bundle-plugin 强制为 3.3.0