Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot inject PageBuilderService without @Scanned annotation

Alex Crimi March 5, 2018

I have a webwork action that I'm trying to inject PageBuilderService as well as a custom service class into. It looks like this:

 

public class CustomAction extends ProjectActionSupport {

@Inject
public CustomAction(@ComponentImport PageBuilderService pageBuilderService,
@ComponentImport CustomService customService) {
...
}
}

According to the spring scanner readme, I should not add the @Scanned annotation to this class, because all classes are scanned by default (I have followed the steps to configure my plugin for Scanner 2.x+). However, omitting it gives me this error when I try to load the url for the action:

No qualifying bean of type [com.atlassian.webresource.api.assembler.PageBuilderService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.

Adding @Scanned fixes this (even though it seems like I shouldn't have to do it), BUT it also breaks the injection of my CustomService. The plugin can't even be enabled when building and eventually times out with this error:

Plugin 'com.myplugin' never resolved service '&customService' with filter '(&(objectClass=com.myplugin.CustomService)(objectClass=com.myplugin.CustomService))

My CustomService is a basic service interface for using ActiveObjects, which is implemented as follows:

@Named
public class CustomServiceImpl implements CustomService {

@ComponentImport
private final ActiveObjects activeObjects;

@Inject
public CustomServiceImpl(ActiveObjects activeObjects) {
this.activeObjects = activeObjects;
}
}

  I have tried passing parameters to @Named, adding @ExportAsService, none of which seems to help

Basically, I can get the injection of the atlassian class or my class working, but not at the same time.

1 answer

1 accepted

2 votes
Answer accepted
Alexey Matveev
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.
March 5, 2018

CustomService must be injected without @ComponentImport annotation. You inject only external to your plugin services with the ComponentService annotation.

public class CustomAction extends ProjectActionSupport {

@Inject
public CustomAction(@ComponentImport PageBuilderService pageBuilderService,
CustomService customService) {
...
}
}
Alex Crimi March 6, 2018

Perfect, can't believe I missed something so simple.

Do you have any idea why the @Scanned annotation is still necessary though, despite the docs?

Alexey Matveev
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.
March 6, 2018

I am not sure about the configurations in your project. But it must work without @Scanned annotation

Alex Crimi March 7, 2018

Adding @Named to my CustomAction class instead of @Scanned fixed it.  The readme isn't super clear, but I guess you're expected to use @Named/@Component on classes using dependency injection?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events