Why is there an org.springframework.beans.factory.UnsatisfiedDependencyException for a basic Confluence Macro Plugin?

Tim Colson November 4, 2015

I'm running through the (old) Confluence Macro Tutorial from Atlassian. Rather than download the 500+ MB of source (the /target dir is in the initial checkin!), I created a new plugin and pasted in the Example Macro source, and config info.

Server runs, but on bringing up the macro browser, an error is thrown it the console.

 

[INFO] [talledLocalContainer] 2015-11-04 23:17:33,530 ERROR [http-nio-1990-exec-10] [atlassian.plugin.module.PrefixDelegatingModuleFactory] createModule Detected an error instantiating the module via Spring. This usually means that you haven't created a <component-import> for the interface you're trying to use. https://developer.atlassian.com/x/TAEr  for more details.
[INFO] [talledLocalContainer]  -- referer: http://127.0.0.1:1990/confluence/pages/editpage.action?pageId=98310 | url: /confluence/plugins/macrobrowser/browse-macros.action | userName: admin | action: browse-macros

[INFO] [talledLocalContainer] 2015-11-04 23:17:33,560 WARN [http-nio-1990-exec-10] [impl.macro.metadata.AllMacroMetadataCache] lambda$loadMacroMetadata$165 Failed to make metadata for module 'com.cisco.macrotest:my-macro': Error creating bean with name 'com.cisco.ExampleMacro': Unsatisfied dependency expressed through constructor argument with index 0 of type [com.atlassian.confluence.xhtml.api.XhtmlContent]: : No unique bean of type [com.atlassian.confluence.xhtml.api.XhtmlContent] is defined: Unsatisfied dependency of type [interface com.atlassian.confluence.xhtml.api.XhtmlContent]: expected at least 1 matching bean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.atlassian.confluence.xhtml.api.XhtmlContent] is defined: Unsatisfied dependency of type [interface com.atlassian.confluence.xhtml.api.XhtmlContent]: expected at least 1 matching bean

 

I'm using Atlas plugin 6.1.0 and it's generating a maven pom.xml with Confluence 5.8.15:

<confluence.version>5.8.15</confluence.version>
<confluence.data.version>5.8.8</confluence.data.version>
<amps.version>6.1.2</amps.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
<atlassian.spring.scanner.version>1.2.6</atlassian.spring.scanner.version>

 

For grins, I even added a component-import config to the atlassian-plugin.xml, but no luck.

<component-import key="xhtmlContent" interface="com.atlassian.confluence.xhtml.api.XhtmlContent"/>"

 

 

7 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Tim Colson (Cisco) January 26, 2016

Learned more... seems like the "instructions" block provides info about how to process the dependencies into OSGI Bundles. Problem there was that it seems to have prevented correct packaging of the Atlassian libs.

Removing this section made the UserAccessor injectable.

 

&lt;instructions&gt;
    &lt;Atlassian-Plugin-Key&gt;${atlassian.plugin.key}&lt;/Atlassian-Plugin-Key&gt;
    &lt;!-- Add package to export here --&gt;
    &lt;Export-Package&gt;
        com.yourcompany.api,
    &lt;/Export-Package&gt;
    &lt;!-- Add package import here --&gt;
    &lt;Import-Package&gt;
        org.springframework.osgi.*;resolution:="optional",
        org.eclipse.gemini.blueprint.*;resolution:="optional",
        *
    &lt;/Import-Package&gt;
    &lt;!-- Ensure plugin is spring powered - see https://extranet.atlassian.com/x/xBS9hQ  --&gt;
    &lt;Spring-Context&gt;*&lt;/Spring-Context&gt;
&lt;/instructions&gt;
sixenvi February 17, 2016

Thank you so much! After deleting these instructions my plugin finally worked "again".

Roman Bubiakin _Wombats Corp_ April 17, 2017

Thank u one more time!

You saved so much time for me spended for fighting with super-fast-new-way-to-package

Like Roma Bubyakin likes this
1 vote
Tim Colson November 4, 2015

Does Atlassian ever actually QA the basic macro/plugin dev tutorials anymore? The macro page says this was last updated in 2013 and tested with 5.2!

0 votes
Tim Colson (Cisco) January 28, 2016

Thanks, Steve. I converted it into an answer so others will see it, but will ask the developer (Anurag) who found it to post it as The Answer so I don't take credit for something he figured out. smile

0 votes
Steve Kling January 28, 2016

@Tim Colson (Cisco)  Thanks for this ^ last post.  This is exactly what the problem was.  Interestingly enough its added automatically in the pom by atlas-create-confluence-rest-module!  Go figure.  The "resolution:=optional" is particularly insidious as it a) not recommended to use and b) hides version conflict errors at startup in favor of much more bewildering UnsatisfiedDependencyExceptions. 

0 votes
Tim Colson November 13, 2015

Some good news... I've learned that unless you need to process the page body, you don't need the XhtmlContent object, so just ditch it. That said, I do need the UserAccessor, and it throws the same error. Well, it did b/c I had the "wrong one". Then I picked the correct package, and it seemed to work for about 4 hours, and then it stopped working. Seriously. As a workaround, I'm grabbing that devil from the Velocity Context (yes, egregious hack, but it works all the time, dammit) -> UserAccessor userAccessor = (UserAccessor) context.get("userAccessor");

0 votes
Deleted user November 12, 2015

I'm having the exact same issue - tried doing what Patrick suggested but no give.

0 votes
masopust November 11, 2015

I found that sometimes importing components this way fails, but works when defining the interface as child element rather than attribute.

 

For example I couldn't get the SAL Transaction Template to work this way, but when using

&lt;component-import name="SAL Transaction Template" key="transactionTemplate"&gt;
	    &lt;interface&gt;com.atlassian.sal.api.transaction.TransactionTemplate&lt;/interface&gt;
	&lt;/component-import&gt;

Spring injection works like a charm. Maybe that'll help in your case, too?

Tim Colson November 13, 2015

Thanks for the idea, Patrick. I just gave this a try, still fails with the same error: <component-import name="User Accessor" key="userAccessor"> <interface>com.atlassian.confluence.user.UserAccessor</interface> </component-import>

masopust November 16, 2015

Just to make sure: is the component import showing up in your plugin modules? You would find these on the addon administration screen. Still, UserAccessor should not need a component import in first place. Have you tried both injection via setter and constructor?

Tim Colson November 16, 2015

I did try both, even though I believe setter injection is not recommended for Plugins2. Constructor fails with no beans available, and setter fails later with an NPE.

Steve Kling January 26, 2016

I'd sure love to know how to solve this.  It seems dependency injection simply doesn't work at all for UserAccessor.  Confluence 5.9.  SDK 6.2.2.  Have some functionality dead-in-the-water.  Every single time it generates a NoSuchBeanDefinition exception.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events