Unable to inject ComponentLocator

Hello Guys,
I"m trying to inject ComponentLocator in my class, but, I"m still getting the following exception:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.atlassian.jira.util.ComponentLocator] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

@Scanned
public class CRMCompanySearcher  {
		
	@ComponentImport
	private final ComponentLocator componentLocator;
public CRMCompanySearcher( final ComponentLocator componentLocator) {
		this.componentLocator = componentLocator ;
	}
.
.
.
}

Did I miss something? Can you please help?
thanks,
Rosy

This is wrong: Do not inject ComponentLocator. Daniel has good suggestions below.

Hello @sfbehnke,

Unfortunately, it didn’t work :frowning:

thanks,
Rosy

ComponentLocator is not injectable. The methods on it are static so you can just do ComponentLocator.getInstance(YourClass.class)

That said - ComponentLocator should only be used as a last case of when you can get hold of something. You really should inject services/managers directly when you can.

1 Like

thanks a lot @daniel!