使用JBoss Fuse启动bundle时的BeanCreationException

时间:2017-10-23 12:27:41

标签: java jbossfuse

我创建了maven项目,将其余的web服务暴露给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命令:

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

捆绑ID:333

JBossFuse:karaf @根&GT; START 333 - &gt;给我这个例外: org.springframework.beans.factory.BeanCreationException:创建名称为&#39; restService&#39;的bean时出错:bean的初始化失败;嵌套异常是java.lang.NullPointerException

我正在使用JBoss Fuse 6.3和java 1.8

2 个答案:

答案 0 :(得分:1)

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>

答案 1 :(得分:0)

另外我注意到jaxrs:服务器地址=“http:// localhost:9000 / employeeservice,这意味着你使用独立的jetty端口9000.但是,当你部署到FUSE容器(基于Karaf / OSGi)时,最佳实践是使用容器管理的servlet传输(默认情况下为端口8181),因此请改用相对地址, public class SocketServerUdpHandler{ // ports private int _port = 0; private int _localAssignedPort = 0; // udp client private UdpClient _clientUdp = null; private IPEndPoint recvEndP = new IPEndPoint( IPAddress.Any, 0); //********** START ********** public bool StartUdp(int po){ // port set by user _port = po; // client bool created = CreateClient(); // start it up if(created){ FindLocalAssignedPort(); StartListen(); } return created; } //********** LISTENER ********** private bool CreateClient(){ // state bool success = true; try{ // udp client _clientUdp = new UdpClient(); }catch(Exception e){ success = false; } return success; } private void StartListen(){ // listen _clientUdp.BeginReceive(new AsyncCallback(ReceiveCallback), null); } private void ReceiveCallback(IAsyncResult ar){ // read incoming byte[] receiveBytes = _clientUdp.EndReceive(ar, ref recvEndP); // handle bytes ... // listen StartListen(); } private void FindLocalAssignedPort(){ IPEndPoint tmpEndP = new IPEndPoint( IPAddress.Parse("127.0.0.1"), 10001 ); byte[] msgByte = new byte[] {(byte) 9}; _clientUdp.Client.SendTo(msgByte, tmpEndP); _localAssignedPort = ((IPEndPoint) _clientUdp.Client.LocalEndPoint).Port; } //********** SEND TO ********** public void writeSocketToEndPoint(IPEndPoint ipEndP, byte[] bytes){ _clientUdp.Client.SendTo(bytes, ipEndP); } } 然后您可以通过http://localhost:8181/cxf/employeeservice

访问端点

弗里曼