In DS only one constructor may have the @Activate annotation. However this is only evaluated at compile time and for constructors only leads to generating the init attribute in the component descriptor.
If you have multiple public constructors taking the same amount of parameters (and all having a type which is potentially valid for constructor injection) an arbitrary one may be chosen by DS implementations. Compare with
https://docs.osgi.org/specification/osgi.cmpn/8.0.0/service.component.html#service.component-constructor.injection
If more than one constructor remains, this implies the constructor is overloaded and SCR may choose any of the remaining constructors to construct the component instance.
This should at least lead to a WARNING with bnd as this may lead to subtle bugs which are hard to trace down.
Example:
@Component
public class TestComponent {
public TestComponent(BundleContext context) {
}
@Activate
public TestComponent(Map<String, Object> properties) {
}
}
In DS only one constructor may have the
@Activateannotation. However this is only evaluated at compile time and for constructors only leads to generating theinitattribute in the component descriptor.If you have multiple public constructors taking the same amount of parameters (and all having a type which is potentially valid for constructor injection) an arbitrary one may be chosen by DS implementations. Compare with
https://docs.osgi.org/specification/osgi.cmpn/8.0.0/service.component.html#service.component-constructor.injection
This should at least lead to a WARNING with bnd as this may lead to subtle bugs which are hard to trace down.
Example: