2016-12-15 2 views
-1

Мой Activator Класс:Как развернуть мое приложение загрузки Spring в контейнер Equinox OSGi. Получение 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) 

Здесь Bundle-Activator: com.package.actprovider. Активатор, но файл activator.class создания в/BOOT-INF/классов/пакет com.package.actprovider.Activator

мой 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 container

ответ

0

Весенняя обувь и OSGi являются взаимоисключающими. Вы можете использовать весну до определенной степени, но даже это плохо работает.

Таким образом, наилучшей практикой является создание приложений OSGi на основе декларативных услуг или плана. Вы также можете взглянуть на Apache Karaf для поддержки таких технологий, как JPA, сервлеты ...

Это будет немного больше усилий, чем весенний ботинок, но вы сможете решить те же проблемы.

Смежные вопросы