-2

I have one bundle Activator class and some of codes there. I need to use @Autowired inside my bundle activator class. It is not working. Here is my bundle Activator class,

public class ProviderActivator implements BundleActivator {

    @Autowired
    public TestingClass testingClass;

    public void start(final BundleContext bundleContext) throws Exception {
        System.out.println("bundle starter!!!!!!!!!!!!!!" +testingClass );
        }
}

testingClass SOP is null. Spring context scanning added in spring-context.xml.

here my suggestion is,

the bean injected after bundleActivator class loaded.

How to prevent that? why the bean is null when startup bundle class?

Sridhar
  • 89
  • 7
  • Hi @Sridhar it dependends how your bundle is started. If you use pure Java, or Spring or Blueprint. Blueprint is very similar to Spring, you use an XML file to configure beans and inject into other classes. You may want to read this: http://blog.knowhowlab.org/2010/10/osgi-tutorial-4-ways-to-activate-code.html – Alessandro Da Rugna Jan 23 '17 at 08:02
  • Then please edit your question and specify how you activate your bundle – Alessandro Da Rugna Jan 23 '17 at 08:03

1 Answers1

0

Why would you even expect this to work? The activator class is instantiated by the OSGi Framework, and @Autowired is not an OSGi feature.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77