1

我用 Maven、CXF 和 spring 创建了一个 Restful 服务。对于 Maven 原型,我选择快速入门。这是 pom.xml:

<groupId>com.example.ExampleBean</groupId>
<artifactId>RestExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>

<build>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

pom依赖:

<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-rt-frontend-jaxrs</artifactId>
  <version>2.3.0</version>
</dependency>

班级:

package com.example.ExampleBean;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/example")
public class RestExample {
@GET
    @Path("/")
    public String ping() throws Exception {
        return "SUCCESS";
    }
}

src/main/resources/META-INF/spring/bundle-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
     http://www.springframework.org/schema/beans    
     http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd
     http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>


<bean id="exampleBean" class="com.example.ExampleBean.RestExample" />

<jaxrs:server id="exampleService" address="/">
    <jaxrs:serviceBeans>
        <ref bean="exampleBean" />
    </jaxrs:serviceBeans>
</jaxrs:server>

</beans>

maven安装成功。当我将包部署到 Fuse ESB karaf OSGi 容器并启动它时,我得到:

[ 286] [活动] [] [失败] [60] RestExample (0.0.1.SNAPSHOT)

它未能启动。谁能帮我这个?

4

0 回答 0