How to get CacheManager and ClusterMessagingService components in a singleton class without spring scanner

How to get CacheManager and ClusterMessagingService components in a singleton class without spring scanner?
I have a requirement in Jira app development where spring scanner is not available and need to get predefined Jira components like CacheManager and ClusterMessagingService in a singleton class where we can not inject these components through constructor injection.

1 Like

Hello Nagesh,

If I understand your problem correctly you simply need to create your kind of own ‘ComponentAccessor’ class, create an accessor class in your package where you use component injection for both ClusterMessaginService and CacheManager and then create your own instance of this class and get these objects to use them

If this still doesn’t solve it for you, or for some reason you find it not compliant with your design; rethink your design

Thanks, @kallas.christian for your reply.
I can do everything in your reply except the below, how to create/inject instance for my own accessor class in a singleton class.

then create your own instance of this class and get these objects to use them

I used the below code in my singleton class, created an instance using Atlassian ComponentAccessor class, do you see any issues with it in any of the Jira versions?

ComponentAccessor.getComponent(ClusterMessagingService.class);

That should work fine for you too, but ComponentAccessor should not be a common practice. Try to use Injection as much as you can instead

Basically my suggestion was to create something similar but to have your own accessor instead of calling the class explicitly as you are now

Hope this helped you out :slight_smile:

Hi @kallas.christian,

Any sample code snippet for creating our own accessor class and any code snippet to create instance for our own accessor class in singleton class (as injection is not possible here) would help me if possible.

Thanks,
Nagesh