我想将我的EE应用程序迁移到OSGi。我的应用程序由业务库,数据库JPA /实体和REST/WS接口组成。它也有一个网络客户端。OSGi JAX-RS和bnd声明式服务
我首先进行原型构造,并使所有接口和包以OSGi干净的方式彼此交谈。我希望尽可能使用清晰的规范,而无需任何特定的供应商或框架。
我使用bnd maven插件来生成清单和声明性服务。我想用注射像这样,使我从剩下的资源OSGi服务的呼叫(在另一个bundle):
@Path("some-resources")
@Component
public class SomeResources{
private SomeService service = null;
@Reference
public void setController(SomeService service) { // <- this is never called
this.service = service;
}
@GET
@Produces(javax.ws.rs.core.MediaType.APPLICATION_XML)
public Object getSomeService() { // <- called
try {
service.process("Hello World"); // <- Error null object
}
...
}
我可以标注与BND @Component
和资源可以在@Resource
注入? 一切工作正常,但服务始终为空。
应该如何声明我的捆绑包使BND成为一个web/wab包?
我用maven捆绑:
<packaging>bundle</packaging>
...
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>biz.aQute</groupId>
<artifactId>bndlib</artifactId>
<version>1.50.0</version>
</dependency>
</dependencies>
<configuration>
<supportedProjectTypes>
<supportedProjectType>ejb</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
<supportedProjectType>wab</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>jar</supportedProjectType>
</supportedProjectTypes>
<instructions>
<_include>-osgi.bundle</_include>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
<execution>
<id>bundle-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
...
与BND说明
Web-ContextPath: my-root-http/rest/
Service-Component: *
我最近遇到了类似的问题(服务没有被绑定),并追踪到[split package](http://wiki.osgi.org/wiki/ Split_Packages)问题。您是否尝试将您的服务接口放入单独的包中? – 2012-04-18 07:22:51
谢谢@BjörnPollex的建议。我有3个软件包,一个只有接口,一个带有服务实现和REST bundel。我实际上将它移回到REST bundel,看看这样做是否有效,但没有运气。如果我正在做的事情是正确的,那么可能问题在于SCR找不到我的DS xml。 – Gadi 2012-04-18 07:29:20
感谢编辑@donalfellows – Gadi 2012-04-18 07:30:51