2016-12-15 2 views
-1

マイアクティベータークラス:春分コンテナによって読み取られるEquinox OSGi ContainerにSpring起動アプリケーションをどのように配備できますか? BundleExceptionを取得:読み込みエラーのバンドル・アクティベーター

package com.package.actprovider; 
import org.osgi.framework.BundleActivator; 
import org.osgi.framework.BundleContext; 
import org.osgi.framework.ServiceListener; 
import org.osgi.framework.ServiceRegistration; 
import com.package.Application; 
import org.osgi.framework.ServiceEvent; 

/** 
* This class implements a simple bundle that utilizes the OSGi 
* framework's event mechanism to listen for service events. Upontting 
* receiving a service event, it prints out the event's details. 
**/ 

public class Activator implements BundleActivator , ServiceListener{ 
private ServiceRegistration registration; 
//private Application application; 

/** 
* Implements BundleActivator.start(). Prints 
* a message and adds itself to the bundle context as a service 
* listener. 
* @param context the framework context for the bundle. 
**/ 

@Override 
public void start(BundleContext context) 
{ 
    System.out.println("Starting to listen for service events.++++"); 
    context.addServiceListener(this); 

} 

/** 
* Implements BundleActivator.stop(). Prints 
* a message and removes itself from the bundle context as a 
* service listener. 
* @param context the framework context for the bundle. 
**/ 
@Override 
public void stop(BundleContext context) 
{ 
    context.removeServiceListener(this); 
    System.out.println("Stopped listening for service events."); 
} 

/** 
* Implements ServiceListener.serviceChanged(). 
* Prints the details of any service event from the framework. 
* @param event the fired service event. 
**/ 
public void serviceChanged(ServiceEvent event) 
{ 
    String[] objectClass = (String[]) 
     event.getServiceReference().getProperty("objectClass"); 

    if (event.getType() == ServiceEvent.REGISTERED) 
    { 
     System.out.println(
      "Ex1: Service of type " + objectClass[0] + " registered."); 
    } 
    else if (event.getType() == ServiceEvent.UNREGISTERING) 
    { 
     System.out.println(
      "Ex1: Service of type " + objectClass[0] + " unregistered."); 
    } 
    else if (event.getType() == ServiceEvent.MODIFIED) 
    { 
     System.out.println(
      "Ex1: Service of type " + objectClass[0] + " modified."); 
    } 
} 

} 

MANIFEST.MFファイル:ここで

Manifest-Version: 1.0 
Bundle-Description: A bundle that displays messages at startup and whe 
n service events occur 
Bundle-Name: Service listener example 
Bundle-Version: 1.0.0 
Bundle-Activator: com.package.actprovider.Activator 
Bundle-Vendor: Apache Felix 
Import-Package: org.osgi.framework 
Created-By: 1.8.0_101 (Oracle Corporation) 

バンドル・アクティベーター:com.package.actprovider。 Activatorですが、/ BOOT-INF/classes/packageにあるactivator.classファイルcom.package.actprovider.Activator

my pom.xmlは次のとおりです

http://maven.apache.org/xsd/maven-4.0.0.xsd "> 4.0.0

<groupId>com.package</groupId> 
<artifactId>myfoo</artifactId> 
<version>0.1.0</version> 
<packaging>bundle</packaging> 



<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.4.0.RELEASE</version> 
    <relativePath /> 
</parent> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <executions> 
      <execution> 
       <phase>none</phase> 
      </execution> 
     </executions> 
     </plugin> 
     <!-- tag::plugin[] --> 
     <plugin> 
      <groupId>com.spotify</groupId> 
      <artifactId>docker-maven-plugin</artifactId> 
      <version>0.4.9</version> 
      <configuration> 
       <imageName>${docker.image.prefix}/${project.artifactId}</imageName> 
       <dockerDirectory>src/main/docker</dockerDirectory> 
       <resources> 
        <resource> 
         <targetPath>/</targetPath> 
         <directory>${project.build.directory}</directory> 
         <include>${project.build.finalName}.jar</include> 
        </resource> 
       </resources> 
      </configuration> 
     </plugin> 


     <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> 
      <configuration> <archive> <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> 
      </archive> </configuration> </plugin> --> 
     <plugin> 
\ 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <extensions>true</extensions> 

      <configuration> 
       <archive> 
        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> 
       </archive> 
      </configuration> 
     </plugin> 

    </plugins> 
</build> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>sdp-api-java</groupId> 
     <artifactId>sdp-api-java</artifactId> 
     <version>1.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-configuration-processor</artifactId> 
     <optional>true</optional> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jersey</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.apache.felix.framework</artifactId> 
     <version>2.0.4</version> 
    </dependency> 
</dependencies> 

私は内部のスプリング・ブート・バンドルを追加する方法を提案してくださいosgiコンテナ

答えて

0

スプリングブートとOSGiは互いに排他的です。あなたはある程度の春を使用することができますが、それはひどくうまくいきます。

したがって、宣言型サービスまたは青写真に基づいてOSGiアプリケーションを構築することがベストプラクティスです。また、JPA、サーブレットなどの技術をサポートするためにApache Karafを見てみることもできます。

これは春の起動時よりも少し労力がありますが、同じ問題を解決できるはずです。

関連する問題