Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Why won't the Bitbucket Server AvatarService get auto-wired into my plugin?

Graham Lea December 3, 2015

I have in my atlassian-plugin.xml:

<component-import key="avatarService" interface="com.atlassian.bitbucket.avatar.AvatarService"/>

And a constructor on my plugin that looks like this:

public PluginImpl(GitCommandBuilderFactory gitCommandBuilderFactory, UserService userService, NavBuilder navBuilder, AvatarService avatarService) {

With the AvatarService in the constructor, the plugin won't start up, with Spring complaining:

[INFO] [talledLocalContainer] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'my-plugin' defined in URL [bundle://21.0:0/META-INF/spring/atlassian-plugins-components.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)

However, without the AvatarService in the constructor, everything else is wired up fine.

Why won't AvatarService get autowired?

(I've double-checked that the AvatarService imported in the code matches the one in the plugin XML.)

(I also tried switching to a no-arg constructor with setters for the dependencies and a @PostContruct init() method, but init() was never called.)

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Felix
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 4, 2015

I've tried to reproduce the behaviour you are seeing, where Spring won't auto-wire the AvatarService for you and could not. 

As you correctly assumed, the AvatarService will allow you to retrieve avatars for your described use-case of a SimplePerson, where the "avatarSize" query parameter may be insufficient.  

I've created a small sample plugin you could check out to see if you spot any obvious differences that could cause Spring to misbehave. 

For more in-depth debugging, we'd need to see more code. If you could reproduce the issue in a minimal sample, we can investigate further. 

0 votes
Graham Lea December 13, 2015

D'oh. I forgot that I've got ProGuard setup for this project, and that the constructor signatures have to be explicitly listed in proguard.conf in order for it to work. Hence, add another dependency to the constructor and suddenly Spring can't find it.

0 votes
Graham Lea December 3, 2015

Thanks for the response, Felix. That's helpful for many cases, but it doesn't handle the case where some of the users who've committed are not Bitbucket's users. I want to handle the cases where the committer is either an ApplicationUser or just a SimplePerson I've constructed from an email address (which I'm assuming AvatarService handles?).

0 votes
Felix
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 3, 2015

Why are you trying to use the AvatarService? If it is just to display avatars in the UI based on existing REST responses (from Bitbucket Server's REST API), you can add a "avatarSize=32" (replace "32" with the size of avatar you'd like) as a query param to the REST call, and the avatar URLs will be added to the REST response. For example: http://localhost:7990/bitbucket/rest/api/1.0/admin/users?avatarSize=32 If this doesn't help you, let me know and I'll try to help you get the AvatarService injected properly.

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