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

Components injection with Spring Scanner

Aviram Gabay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2016

Hi team,

I am having some trouble understanding how to make things work with the new version of plugins that includes spring scanners.

I'm trying to inject the UserAccessor object into one of my plugins (A rest module class) but I can't seem to pull it of. I've read all the tutorials about @Component and @Inject annotations that are now used instead of the plugin xml component-import but still couldn't make it work.

It would be great to see a working sample or at least an explanation for someone who only knows basic Maven and Spring.

Thanks!

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

9 votes
Answer accepted
ɹǝʞɐq pɐɹq
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 31, 2016

I'm trying to inject the UserAccessor object into one of my plugins (A rest module class) but I can't seem to pull it of. I've read all the tutorials about @Component and @Inject annotations that are now used instead of the plugin xml component-import but still couldn't make it work.

I am guessing that UserAccessor is in fact an OSGi component being exported by some other part of the system.  If so then you need to tell the SpringScanner runtime that its required as an OSGi "import"

You can do this :



@Scanned
public class ARestModule {
    public ARestModule(@ComponentImport UserAccessor userAccessor) {
      .....

@ Scanned says consider this class as part of something that the scanner build time should consider (like @Coponent / @Inject but without any other side effects)

and  
@ComponentImport says OSGI import this component from outside and make it available to me


For the record "rest modules" are magic in that they do not need to make themselves known to Spring and yet are "wired" for you by the Atlassian plugin system.  But @Scanned is needed here to make the spring-scanner build time take it into consideration. 


 

Aviram Gabay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2016

Hi Brad,

Thanks for your reply, it turns out all was missing was some import packages from the pom.xml

I added them and the suggested annotations by you and it worked!

Thanks!

Tadd Seiff April 15, 2016

For the benefit of others, can you detail the other changes you had to make?  What does your pom look like?

senthilnathansampathkumar January 7, 2017

Annotate your class with @Scanned for spring scanner to work on your class. 

Annotate with @Autowired to wire in an implementation at runtime

Annotate with @ComponentImport to import components

In effect you have to use the above three annotations to use a component

 

@Scanned
public class ARestModule {
    @Autowired
    public ARestModule(@ComponentImport UserAccessor userAccessor) {
    //userAccessor component is available to use
	 .....
1 vote
Chii
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 31, 2016

The README file in the spring scanner repository contains a comprehensive tutorial and there's a sample project in the repo as well : https://bitbucket.org/atlassian/atlassian-spring-scanner/ 

Aviram Gabay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2016

Thanks Joe, I've tried to read through this file several times and still could not make sense of it....

My Spring and Maven knowledge is fairly basic (not even) so for me its really hard to make sense out of the README file

 

Cheers

Tadd Seiff April 15, 2016

I agree with Aviram, the document may be comprehensive but it is not that clear. It is not a tutorial, just a series of disparate examples.

If that is the one and only resource for using the scanner, it needs to be improved. Or better yet, it should be supplemented with an actual tutorial somewhere intuitive, like developers.atlassian.com.

 

JessicaB June 14, 2016

I agree with Aviram and Tadd, for seasoned developers and people trying to learn the newer spring and Atlassian maven conventions having a tutorial or at least an example of how to convert the component-imports to scanners would be helpful to everyone.

@Joe Xie is there anyway to get the documentation for working with the SDK that still has the old plugin component-imports updated?

Steven Kling September 30, 2016

+1 Aviram, Tadd, Jessica.  Developer-written readme is not sufficient support for your add-on development community.  You have to stop treating add-on development as a glorified open-source project to improve add-on quality, feature depth, standards and time-to-market.

Josh Wheeler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 30, 2016

+1

Michiel Roos December 6, 2016

+1

Antonio Petricca October 6, 2017

+1

0 votes
Roman Samorodov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2016

Found answer Here.

TAGS
AUG Leaders

Atlassian Community Events