I’m trying to inject the com.atlassian.sal.api.pluginsettings.PluginSettingsFactory into my class (which extends ConfluenceActionSupport). But no matter what I try, I always get an exception, that the bean is not found: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'net.example.SettingsAction': Unsatisfied dependency expressed through field 'pluginSettingsFactory': No qualifying bean of type 'com.atlassian.sal.api.pluginsettings.PluginSettingsFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject()}
I’ve tried many different combinations of Annotations, but even just using ComponentLocator.getComponent(PluginSettingsFactory.class); does not work, only returning null.
I’ve added com.atlassian.sal.api.*;resolution:="optional" to the Import-Package of the confluence-maven-plugin in the pom.xml, to no effect.
Does anyone knows why I can’t get a hold of the PluginSettingsFactory? I’m testing on Confluence 9.3.2, if that is relevant.
CodeSnippet of my class:
public class ExampleSettingsAction extends ConfluenceActionSupport {
@Inject
@ComponentImport
private PluginSettingsFactory pluginSettingsFactory;
}
First thing I would check in this case is if the sal-api dependency is set to provided scope.
If it’s bundled in the app then the classloaders of the reference in your class and that of the platform-provided service won’t match and injection fails.
Since you seem to use spring-scanner you can also check inside the compiled JAR if there’s a reference to the PluginSettingsFactory class in META-INF/plugin-components/imports.
Thanks for the answer. I have checked, and the sal-api has scope ‘provided’ and there is indeed a PluginSettingsFactory reference in the imports file. So sadly, that was not it.
I’ve dug a bit deeper, and found something that might or might not help with this. Hopefully it will.
I have two other classes in the same plugin. One that has a @Named tag on it, and one a @Component on it. In both classes, I’m injecting the PluginSettingsFactory (just like in the code snippet above). And in both, I get a com.atlassian.sal.confluence.pluginsettings.ConfluencePluginSettingsFactory instance injected, as expected.
I tried to add the @Named annotation to my ExampleSettingsAction, but this did not help. Neither did the @Component annotation.
What might be interesting, even in the working cases, using ComponentLocator.getComponent(PluginSettingsFactory.class); will return null, as if the PluginSettingsFactory was not a valid component.
Might that be helpful for anyone to solve this issue? Or is there maybe another way I could get the PluginSettingsFactory? An idea is to get ahold of the Injection mechanism that Confluence is using, and letting the PluginSettingsFactory getting injected programatically?
I’m writing this for others who might encounter the same problem. I did not manage to get it working in Confluence 9.3.2. But using the same code in Conflunce 10 Milestone 119, it worked without any problem.
So, eh, maybe there was a bug in Confluence 9.x, that is now fixed in Confluence 10?