Last updated Mar 27, 2024

UnsatisfiedDependencyException - error creating bean with name

Symptom: "UnsatisfiedDependencyException: Error creating bean with name", "Unsatisfied dependency expressed through constructor argument with index 1"

Cause: the class is unknown to the OSGI plugin

Solution: add a component-import element in the atlassian-plugin.xml file to import the necessary class. See the Component Import plugin module for an example of what this element does.

Other useful introductions include OSGi, Spring and the Plugin Framework and Automatic Generation of Spring Configuration.

Example:

1
2
2010-02-23 14:15:46,831 http-8080-Processor25 ERROR admin 51345x1x1 1hageqe http://localhost:8080/rest/example/1.0/myplugin 
[atlassian.plugin.servlet.DefaultServletModuleManager] Unable to create filter
com.atlassian.plugin.servlet.util.LazyLoadedReference$InitializationException: 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.example.jira.plugins.MyPlugin': 
Unsatisfied dependency expressed through constructor argument with index 1 of type [com.atlassian.sal.api.user.UserManager]: :
 No unique bean of type [com.atlassian.sal.api.user.UserManager] is defined: 
Unsatisfied dependency of type [interface com.atlassian.sal.api.user.UserManager]: expected at least 1 matching bean; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.atlassian.sal.api.user.UserManager] is defined: 
Unsatisfied dependency of type [interface com.atlassian.sal.api.user.UserManager]: expected at least 1 matching bean
    at com.atlassian.plugin.servlet.util.LazyLoadedReference.get(LazyLoadedReference.java:94)
...

Note that the first argument to the constructor has index 0, not index 1.

Add this to atlassian-plugin.xml so that the plugin knows about the missing class:

1
2
<component-import key="userManager" interface="com.atlassian.sal.api.user.UserManager"/>

A good rule of thumb is to be careful with any class whose package doesn't start with com.atlassian.JIRA

Note that component-import may not always work if the host application exposes more than one bean under the same interface. The safest way is to use Constructor Injection is in combination with @Qualifier Spring annotation. See the Plugin Framework documentation for information on how to use @Qualifier to avoid ambiguity in your constructor.

Beyond DI

If using a component-import doesn't work you may be able to instantiate the object using ManagerFactory.getMyObject()
or ComponentManager.getInstance().getMyObject(), or even ComponentManager.getInstance().getComponentInstanceOfType(MyObject.class).

Rate this page: