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!
Community moderators have prevented the ability to post new answers.
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.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the benefit of others, can you detail the other changes you had to make? What does your pom look like?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 .....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
+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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
+1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Found answer Here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.