EE アプリケーションを OSGi に移行したいと考えています。私のアプリケーションは、ビジネス ライブラリ、データベース JPA/エンティティ、および REST/WS インターフェイスで構成されています。また、Web クライアントも備えています。
まず、構造のプロトタイプを作成し、すべてのインターフェースとバンドルが OSGi のクリーンな方法で相互に通信できるようにします。特定のベンダーやフレームワークを使わずに、できるだけクリーンな仕様を使用したいと考えています。
マニフェストと宣言型サービスを生成するために bnd maven プラグインを使用しています。次のようなインジェクションを使用して、残りのリソースから OSGI サービス (別のバンドル) に呼び出しを行いたいと考えています。
@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
すべて正常に動作しますが、サービスは常に null です。
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: *