英文:
Karaf, cxf and jax-rs - No services have been found
问题
当我安装并启动捆绑包时,没有任何反应,控制台没有输出,而bundle:list
报告它为"Active"。我尝试使用blueprint-web
特性,但在日志中出现了"未找到资源类"的异常。
我的设置:
- jdk 11
- karaf 4.4.3
- cxf 3.3.5
feature:install cxf http
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
我使用的是Maven捆绑插件:
<plugin>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-Version>${pom.version}</Bundle-Version>
<Export-Package>my.base.package.*</Export-Package>
<Import-Package>javax.ws.rs.*
javax.jws.*
*
</Import-Package>
</instructions>
</configuration>
</plugin>
OSGI-INF/blueprint.xml
:
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
<jaxrs:server id="myService" address="/test">
<jaxrs:serviceBeans>
<ref component-id="myServiceBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="myServiceBean" class="my.base.package.impl.MyServiceImpl"/>
MyServiceImpl.java
@Path("/")
public class MyServiceImpl implements MyService{
public AccountStorageServiceImpl() {
System.out.println("MyService starting...");
}
@Path("/hello")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Override
public String hello() {
return "Hello World!"
}
}
我最初在接口中使用了注解,但移动到实现类后希望能有所帮助(但没有)。是否有一些我遗漏的额外配置/特性?
英文:
When I install and start the bundle, nothing happens, no output to the console and bundle:list
reports it as "Active". I've tried using blueprint-web
feature and I was getting No resource classes found
exception in logs.
My setup:
- jdk 11
- karaf 4.4.3
- cxf 3.3.5
feature:install cxf http
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
I'm using maven bundle plugin:
<plugin>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-Version>${pom.version}</Bundle-Version>
<Export-Package>my.base.package.*</Export-Package>
<Import-Package>javax.ws.rs.*
javax.jws.*
*
</Import-Package>
</instructions>
</configuration>
</plugin>
OSGI-INF/blueprint.xml
:
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
<jaxrs:server id="myService" address="/test">
<jaxrs:serviceBeans>
<ref component-id="myServiceBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="myServiceBean" class="my.base.package.impl.MyServiceImpl"/>
MyServiceImpl.java
@Path("/")
public class MyServiceImpl implements MyService{
public AccountStorageServiceImpl() {
System.out.println("MyService starting...");
}
@Path("/hello")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Override
public String hello() {
return "Hello World!";
}
}
I had annotations in the interface at first but moved to the impl class hoping it would help(it didn't).
Is there some additional configuration/feature that I'm missing?
答案1
得分: 0
以下是翻译好的内容:
"As is turns out, project setup is not as hard as it seemed to be." -> "事实证明,项目设置并不像看起来那么困难。"
"Only one dependency is required:" -> "只需要一个依赖项:"
"And the annotations can be on the interface, should also add annotation @Resource
for it to get picked up by cxf:" -> "注解可以在接口上,还应该添加@Resource
注解以供cxf识别:"
"(annotations should be from javax.*
)" -> "(注解应来自javax.*
)"
"Complete setup in case someone stumbles upon this question:" -> "如果有人碰巧遇到这个问题,以下是完整的设置:"
"1. feature:repo-add cxf" -> "1. feature:repo-add cxf"
"2. feature:install cxf blueprint-web" -> "2. feature:install cxf blueprint-web"
"3. bundle:install {bundle}" -> "3. bundle:install {bundle}"
"4. bundle:start {bundle-number}" -> "4. bundle:start {bundle-number}"
"Complete maven-bundle plugin config:" -> "完整的maven-bundle插件配置:"
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.9</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=*</Embed-Dependency>
<Embed-Transitive>false</Embed-Transitive>
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-Version>${pom.version}</Bundle-Version>
<Export-Package>my.package.*</Export-Package>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
英文:
As is turns out, project setup is not as hard as it seemed to be.
Only one dependency is required:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
<scope>compile</scope>
</dependency>
And the annotations can be on the interface, should also add annotation @Resource
for it to get picked up by cxf:
@Resource
@Path("/")
public interface MyService {
@Path("/hello")
@GET
@Produces(MediaType.APPLICATION_JSON)
String hello();
}
(annotations should be from javax.*
)
Complete setup in case someone stumbles upon this question:
- feature:repo-add cxf
- feature:install cxf blueprint-web
- bundle:install {bundle}
- bundle:start {bundle-number}
Complete maven-bundle plugin config:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.9</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=*</Embed-Dependency>
<Embed-Transitive>false</Embed-Transitive>
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-Version>${pom.version}</Bundle-Version>
<Export-Package>my.package.*</Export-Package>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论