Karaf、cxf 和 jax-rs – 未找到任何服务

huangapple go评论90阅读模式
英文:

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
  1. <dependencies>
  2. <dependency>
  3. <groupId>org.apache.cxf</groupId>
  4. <artifactId>cxf-rt-frontend-jaxrs</artifactId>
  5. <version>${cxf.version}</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>javax.ws.rs</groupId>
  9. <artifactId>jsr311-api</artifactId>
  10. <version>1.1.1</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.osgi</groupId>
  14. <artifactId>osgi.core</artifactId>
  15. <version>8.0.0</version>
  16. <scope>provided</scope>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.apache.cxf</groupId>
  20. <artifactId>cxf-rt-transports-http-jetty</artifactId>
  21. <version>${cxf.version}</version>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.apache.cxf</groupId>
  25. <artifactId>cxf-rt-transports-http</artifactId>
  26. <version>${cxf.version}</version>
  27. </dependency>
  28. </dependencies>

我使用的是Maven捆绑插件:

  1. <plugin>
  2. <artifactId>maven-bundle-plugin</artifactId>
  3. <extensions>true</extensions>
  4. <configuration>
  5. <instructions>
  6. <Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=*</Embed-Dependency>
  7. <Embed-Transitive>true</Embed-Transitive>
  8. <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
  9. <Bundle-Name>${pom.name}</Bundle-Name>
  10. <Bundle-Version>${pom.version}</Bundle-Version>
  11. <Export-Package>my.base.package.*</Export-Package>
  12. <Import-Package>javax.ws.rs.*
  13. javax.jws.*
  14. *
  15. </Import-Package>
  16. </instructions>
  17. </configuration>
  18. </plugin>

OSGI-INF/blueprint.xml:

  1. <cxf:bus>
  2. <cxf:features>
  3. <cxf:logging/>
  4. </cxf:features>
  5. </cxf:bus>
  6. <jaxrs:server id="myService" address="/test">
  7. <jaxrs:serviceBeans>
  8. <ref component-id="myServiceBean" />
  9. </jaxrs:serviceBeans>
  10. </jaxrs:server>
  11. <bean id="myServiceBean" class="my.base.package.impl.MyServiceImpl"/>

MyServiceImpl.java

  1. @Path("/")
  2. public class MyServiceImpl implements MyService{
  3. public AccountStorageServiceImpl() {
  4. System.out.println("MyService starting...");
  5. }
  6. @Path("/hello")
  7. @GET
  8. @Produces(MediaType.APPLICATION_JSON)
  9. @Override
  10. public String hello() {
  11. return "Hello World!"
  12. }
  13. }

我最初在接口中使用了注解,但移动到实现类后希望能有所帮助(但没有)。是否有一些我遗漏的额外配置/特性?

英文:

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
  1. <dependencies>
  2. <dependency>
  3. <groupId>org.apache.cxf</groupId>
  4. <artifactId>cxf-rt-frontend-jaxrs</artifactId>
  5. <version>${cxf.version}</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>javax.ws.rs</groupId>
  9. <artifactId>jsr311-api</artifactId>
  10. <version>1.1.1</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.osgi</groupId>
  14. <artifactId>osgi.core</artifactId>
  15. <version>8.0.0</version>
  16. <scope>provided</scope>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.apache.cxf</groupId>
  20. <artifactId>cxf-rt-transports-http-jetty</artifactId>
  21. <version>${cxf.version}</version>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.apache.cxf</groupId>
  25. <artifactId>cxf-rt-transports-http</artifactId>
  26. <version>${cxf.version}</version>
  27. </dependency>
  28. </dependencies>

I'm using maven bundle plugin:

  1. <plugin>
  2. <artifactId>maven-bundle-plugin</artifactId>
  3. <extensions>true</extensions>
  4. <configuration>
  5. <instructions>
  6. <Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=*</Embed-Dependency>
  7. <Embed-Transitive>true</Embed-Transitive>
  8. <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
  9. <Bundle-Name>${pom.name}</Bundle-Name>
  10. <Bundle-Version>${pom.version}</Bundle-Version>
  11. <Export-Package>my.base.package.*</Export-Package>
  12. <Import-Package>javax.ws.rs.*
  13. javax.jws.*
  14. *
  15. </Import-Package>
  16. </instructions>
  17. </configuration>
  18. </plugin>

OSGI-INF/blueprint.xml:

  1. <cxf:bus>
  2. <cxf:features>
  3. <cxf:logging/>
  4. </cxf:features>
  5. </cxf:bus>
  6. <jaxrs:server id="myService" address="/test">
  7. <jaxrs:serviceBeans>
  8. <ref component-id="myServiceBean" />
  9. </jaxrs:serviceBeans>
  10. </jaxrs:server>
  11. <bean id="myServiceBean" class="my.base.package.impl.MyServiceImpl"/>

MyServiceImpl.java

  1. @Path("/")
  2. public class MyServiceImpl implements MyService{
  3. public AccountStorageServiceImpl() {
  4. System.out.println("MyService starting...");
  5. }
  6. @Path("/hello")
  7. @GET
  8. @Produces(MediaType.APPLICATION_JSON)
  9. @Override
  10. public String hello() {
  11. return "Hello World!";
  12. }
  13. }

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插件配置:"

  1. <plugin>
  2. <groupId>org.apache.felix</groupId>
  3. <artifactId>maven-bundle-plugin</artifactId>
  4. <version>5.1.9</version>
  5. <extensions>true</extensions>
  6. <configuration>
  7. <instructions>
  8. <Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=*</Embed-Dependency>
  9. <Embed-Transitive>false</Embed-Transitive>
  10. <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
  11. <Bundle-Name>${pom.name}</Bundle-Name>
  12. <Bundle-Version>${pom.version}</Bundle-Version>
  13. <Export-Package>my.package.*</Export-Package>
  14. <Import-Package>*</Import-Package>
  15. </instructions>
  16. </configuration>
  17. </plugin>
英文:

As is turns out, project setup is not as hard as it seemed to be.
Only one dependency is required:

  1. <dependency>
  2. <groupId>org.apache.cxf</groupId>
  3. <artifactId>cxf-rt-frontend-jaxrs</artifactId>
  4. <version>${cxf.version}</version>
  5. <scope>compile</scope>
  6. </dependency>

And the annotations can be on the interface, should also add annotation @Resource for it to get picked up by cxf:

  1. @Resource
  2. @Path("/")
  3. public interface MyService {
  4. @Path("/hello")
  5. @GET
  6. @Produces(MediaType.APPLICATION_JSON)
  7. String hello();
  8. }

(annotations should be from javax.*)

Complete setup in case someone stumbles upon this question:

  1. feature:repo-add cxf
  2. feature:install cxf blueprint-web
  3. bundle:install {bundle}
  4. bundle:start {bundle-number}

Complete maven-bundle plugin config:

  1. <plugin>
  2. <groupId>org.apache.felix</groupId>
  3. <artifactId>maven-bundle-plugin</artifactId>
  4. <version>5.1.9</version>
  5. <extensions>true</extensions>
  6. <configuration>
  7. <instructions>
  8. <Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=*</Embed-Dependency>
  9. <Embed-Transitive>false</Embed-Transitive>
  10. <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
  11. <Bundle-Name>${pom.name}</Bundle-Name>
  12. <Bundle-Version>${pom.version}</Bundle-Version>
  13. <Export-Package>my.package.*</Export-Package>
  14. <Import-Package>*</Import-Package>
  15. </instructions>
  16. </configuration>
  17. </plugin>

huangapple
  • 本文由 发表于 2023年5月28日 03:32:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76348700.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定