0
votes

new to OSGI.

I use spring-boot in OSGI. In bundle activator, spring-boot application starts up successfully. I have a component class as below

@Service // spring-boot annotation
@Component(immediate = true) // osgi annotation
public class Test {
    @Activate
    public void activate() {
        System.out.println("osgi component activated");
    }

    @Reference
    public void set(ServiceComponentXXX a) {
        System.out.println("reference got");
}

The class Test only binds services and are not binded by any other. The class ServiceComponnetXXX is from other bundle. the activate and set methods are never executed.

After remove spring-boot annotation @Service, code works fine. so the question is that can a class be both a spring-boot component and an OSGI component?

1

1 Answers

4
votes

It does not really make sense to make a class be both. The lifecycles of spring boot and declarative services are completely separate. So in best case you end up with two instances of the class - One populated by spring boot and the other by declarative services - but it is a lot more likely that it just does not work.

I suggest to decide if you want to go OSGi. If yes then jut use declarative services and not spring boot. In general decide for one injection framework. In OSGi you can have one injection framework by bundle but they have to be OSGi compatible. Spring boot is not really OSGi compatible.