2016-12-15 43 views
-1

我Activator类:由春分点容器读如何在Equinox OSGi容器中部署我的Spring Boot应用程序。获取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

我的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

Spring引导和OSGi是互斥的。你可以在一定程度上使用弹簧,但即使这样也不好。

所以最好的做法是建立基于声明性服务或蓝图的OSGi应用程序。你也可以看看Apache Karaf支持JPA,servlets等技术......

这将比春季启动多一点努力,但你应该能够解决同样的问题。

相关问题