Converting Confluence Plugin to Spring Scanner: No qualifying bean of type 'com.atlassian.webresourc
Asked by Anna Teng:

I'm converting my Confluence Plugin to Atlassian Spring Scanner 2.1.7. It compiles but I'm getting the following error at runtime:

```
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.atlassian.webresource.api.assembler.PageBuilderService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport(value="")}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1662)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1221)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1175)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)
... 617 more??
```

Here's a snippet of the class:

```
import com.atlassian.webresource.api.assembler.PageBuilderService;
import com.atlassian.confluence.setup.bandana.ConfluenceBandanaContext;
import com.atlassian.confluence.xhtml.api.XhtmlContent;

import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MyMacro extends BaseMacro implements Macro {
private final XhtmlContent xhtmlUtils;
private BandanaManager bandanaManager;
private PageBuilderService pageBuilderService;

@Autowired
public MyMacro(@ComponentImport PageBuilderService pageBuilderService, @ComponentImport XhtmlContent xhtmlUtils, @ComponentImport BandanaManager bandanaManager) {
   this.pageBuilderService = pageBuilderService;
   this.xhtmlUtils = xhtmlUtils;
   this.bandanaManager = bandanaManager;
}

...
}
```

pom.xml:

```
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

... 

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.0.10.RELEASE</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.10.RELEASE</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.atlassian.sal</groupId>
<artifactId>sal-api</artifactId>
<version>4.4.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.atlassian.confluence</groupId>
<artifactId>confluence</artifactId>
<version>${confluence.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-all</artifactId>
<version>0.61.30</version>
</dependency>

<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-ext-anchorlink</artifactId>
<version>0.61.30</version>
</dependency>

<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-ext-autolink</artifactId>
<version>0.61.30</version>
</dependency>

<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-ext-superscript</artifactId>
<version>0.61.30</version>
</dependency>

<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-ext-youtube-embedded</artifactId>
<version>0.61.30</version>
</dependency>

<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-ext-toc</artifactId>
<version>0.61.30</version>
</dependency>

<dependency>
<!-- jsoup HTML parser library @ https://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>

<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>owasp-java-html-sanitizer</artifactId>
<version>20191001.1</version>
</dependency>

<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-webresource</artifactId>
<version>4.1.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.3</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.3</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.10.3</version>
</dependency>

<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>${plugin.testrunner.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.3</version>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>confluence-maven-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${confluence.version}</productVersion>
<productDataVersion>${confluence.data.version}</productDataVersion>
<enableQuickReload>true</enableQuickReload>
<enableFastdev>false</enableFastdev>
<instructions>
<Atlassian-Plugin-Key>${project.groupId}.${project.artifactId}</Atlassian-Plugin-Key>
<Spring-Context>*</Spring-Context>
<Export-Package>
</Export-Package>
<Import-Package>
com.atlassian.confluence.xhtml.api,
com.atlassian.webresource.api.assembler,
com.atlassian.bandana,
org.springframework.stereotype,
org.springframework.beans.factory.annotation,
*; resolution:="optional"
</Import-Package>
</instructions>
<skipManifestValidation>true</skipManifestValidation>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<!-- process-classes seems to be skipped if you are using scala
so perhaps use prepare-package -->
<phase>process-classes</phase> 
</execution>
</executions>
<configuration>
<!-- Enable this to get build-time logging of annotations atlassian-spring-scanner-maven-plugin has noticed -->
<verbose>false</verbose>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<confluence.version>6.9.0</confluence.version>
<confluence.data.version>6.9.0</confluence.data.version>
<amps.version>8.0.4</amps.version>
<plugin.testrunner.version>1.1</plugin.testrunner.version>
<atlassian.spring.scanner.version>2.1.7</atlassian.spring.scanner.version>
</properties>
...
</project>
```

I've mainly been working off the Atlassian Spring Scanner documentation: <https://bitbucket.org/atlassian/atlassian-spring-scanner/src/master/>

I've tried using Inject / Named in place of Autowired / Component, no difference

When I check the compiled .jar's META-INF/plugin-components, I see 2 files:

- component, which lists the class I marked [@Component](/t5/user/viewprofilepage/user-id/1011925)

- imports, which contains the 3 classes I marked @ComponentImport:

```
com.atlassian.bandana.BandanaManager
com.atlassian.confluence.xhtml.api.XhtmlContent
cont.atlassian.webresource.api.assembler.PageBuilderService
```


Answers:
author: Jack Brickey
body: [Duplicate post](https://community.atlassian.com/t5/Confluence-questions/Converting-Confluence-Plugin-to-Spring-Scanner-No-qualifying/qaq-p/1428480)


Tags: component

confluence-server

javascript

maven

server

spring

spring-scanner