0
votes

I have 3 classes , one is Activator and two others, 'mysqlConfiguration' and 'BinaryLogListner' where 'mysqlConfiguration' is injected into 'BinaryLogListner' using blueprint.

This is my blueprint (the injection part):

<bean id="binaryLogListnerBean" class="cdc.mysql.BinaryLogListner">
    <property name="mysqlConfiguration" ref="configManagementMysql"></property>
</bean>

I want to start the BinaryLogListner when the bundle starts , so I instanciated it from the Activator class with :

BinaryLogListner binaryLogListner = new BinaryLogListner();

When i try to use 'mysqlConfiguration' which is injected into 'BinaryLogListner' I will get a null pointer Exception.

I want to know how to inject a bean into an activator, is this possible ? Any thougts how to start beans in these situations?

1

1 Answers

3
votes

In the Activator you instantiate the class using new BinaryLogListner(). So you simply get the plain class without any blueprint injects. These injects only work when the bean instance is created by blueprint.

Instead of an Activator you should simply use an init-method on any blueprint bean to react on the (blueprint) activation of the bundle.

Generally whenever you use blueprint in a bundle you should not also use an Activator.