我使用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 /主/资源/ META-INF /弹簧/捆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 install成功。当我将捆绑包部署到Fuse ESB karaf OSGi容器并启动它时,我得到了:
[286] [有效] [] [失败] [60] RestExample(0.0.1.SNAPSHOT)
未能启动。任何人都可以帮我这个吗?