Search code examples
javajbossfuse

BeanCreationException when starting bundle using JBoss Fuse


I created maven project to expose rest web service to jboss fuse:

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 commands:

JBossFuse:karaf@root>install mvn:com.javainuse/apache-camel-jaxrs/0.0.1-SNAPSHOT

Bundle ID: 333

JBossFuse:karaf@root> START 333 -> give me this exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restService': Initialization of bean failed; nested exception is java.lang.NullPointerException

I am using JBoss Fuse 6.3 and java 1.8


Solution

  • Your Maven POM needs to specify bundle as the packaging type:

    <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>bundle</packaging>
    
        ...
    </project>