0

I started creating an OSGI project with Spring DM. I Created two bundles, the first one (bundle1) provides a service that changes the order of a recieved string. The seconde one (bundle2) consumes that service and prints the result in the console. service implementation:

public final class Bundle1ServiceImpl implements Bundle1Service {

public Bundle1ServiceImpl() {
    System.out.println("Bundle1ServiceImpl contructor...");
}

public String scramble(String text) {
    List charList = new ArrayList();

    char[] textChars = text.toCharArray();
    for (int i = 0; i < textChars.length; i++) {
        charList.add(new Character(textChars[i]));
    }

    Collections.shuffle(charList);

    char[] mixedChars = new char[text.length()];
    for (int i = 0; i < mixedChars.length; i++) {
        mixedChars[i] = ((Character) charList.get(i)).charValue();
    }

    return new String(mixedChars);
}}

spring file for service provider :

bundle1-osgi.xml

<service ref="bundle1Service" interface="fr.thispro.bundle1.Bundle1Service" />

bundle1-context.xml

<bean id="bundle1Service" class="fr.thispro.bundle1.internal.Bundle1ServiceImpl">
</bean> 

consumer :

public class Bundle2Consumer {

private final Bundle1Service service;

public Bundle2Consumer(Bundle1Service service) {
    this.service = service;
}

public void start() {
    System.out.println(service.scramble("Text"));

    System.out.println("im started");
}

public void stop() {
    System.out.println("im stopped");

}}

spring files for consumer: bundle2-context.xml

  <beans:bean id="consumer" class="fr.thispro.bundle2.Bundle2Consumer" init-method="start" destroy-method="stop" lazy-init="false" ><beans:constructor-arg ref="bundle1Service"/>

bundle2-osgi.xml

<reference id="bundle1Service" interface="fr.thispro.bundle1.Bundle1Service" />

The service is well registred referenced and discovered. But the consumer doesn't print anything even when i start it explicitly by start command.

Thanks in adanvance,

user1828433
  • 252
  • 2
  • 11

1 Answers1

0

I found the problem. You bundle2 incldues an Activtor but you did not define the activator in the Manifest. So the bundle never actually starts up.

If you intended to start the bundle2 using spring dm then the problem is that the jar does not contain the spring xml files.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64