Unable in inject MailServerManager with Spring annotations

Dear community,

I’m using MailServerManager in an older plugin successfully (the holding class is defined as component in atlassian-plugin.xml; constructor based injection of MailServerManager w/o Spring annotations).

In a newer plugin which is using Spring scanner annotations I’m unable to inject MailServerManager: No qualifying bean of type [com.atlassian.mail.server.MailServerManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. I try injecting it like all other pieces (e.g. PageManager) which work quite well.

Any idea why only MailServerManager fails?

Thank you

Andreas

It is hard to describe a fix without seeing your class, pom, or plugin descriptor. MailServerManager appears to be exported by System Bundle plugin so it should be possible to inject it.

I

  private final ContentPermissionManager contentPermissionMan;
private final PluginLicenseManager pluginLicenseMan;
private final MailServerManager mailServerMan;
 
private static final Logger log = LoggerFactory.getLogger(SimpleQAHelper.class);
    
private final Cache<String, String> bodyCache;
private final Cache<String, String> queryCache;


@Inject
public SimpleQAHelper(SimpleQARenderCache simpleQARenderCache,
	@ComponentImport PageManager pageMan, @ComponentImport SettingsManager settingsMan,
	@ComponentImport ContentPropertyManager propMan, @ComponentImport NotificationManager notificationMan,
	@ComponentImport UserAccessor userAcc, @ComponentImport PermissionManager permissionMan,
	@ComponentImport CommentManager commentMan, @ComponentImport XhtmlContent xhtmlUtils, @ComponentImport SpaceManager spaceMan,
	@ComponentImport I18nResolver i18n, @ComponentImport TransactionTemplate transactionTemplate,
	@ComponentImport MultiQueueTaskManager mqtm, @ComponentImport BandanaManager bandanaMan,
	@ComponentImport CacheManager cacheMan, @ComponentImport SearchManager searchMan, @ComponentImport LocaleManager localeMan,
	@ComponentImport ContentPermissionManager contentPermissionMan, @ComponentImport PluginLicenseManager pluginLicenseMan,
	@ComponentImport MailServerManager mailServerMan) {
	
	this.pageMan = pageMan;
	this.settingsMan = settingsMan;
	this.propMan = propMan;
	this.notificationMan = notificationMan;
	this.userAcc = userAcc;
	this.permissionMan = permissionMan;
	this.commentMan = commentMan;
	this.xhtmlUtils = xhtmlUtils;
	this.spaceMan = spaceMan;
	this.i18n = i18n;		
	this.transactionTemplate = transactionTemplate;
	this.mqtm = mqtm;
	this.bandanaMan = bandanaMan;
	this.searchMan = searchMan;
	this.localeMan = localeMan;
	this.simpleQARenderCache = simpleQARenderCache;
	this.contentPermissionMan = contentPermissionMan;
	this.pluginLicenseMan = pluginLicenseMan;
	this.mailServerMan = mailServerMan;
<?xml version="1.0" encoding="UTF-8"?>
<modelVersion>4.0.0</modelVersion>
<groupId>de.edrup.confluence.plugins</groupId>
<artifactId>simple-qa</artifactId>

<organization>
    <name>Purde Software</name>
    <url>https://purde-software.atlassian.net/wiki</url>
</organization>

<description>This is the Smart Questions and Answers plugin for Atlassian Confluence.</description>
<packaging>atlassian-plugin</packaging>

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

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

    <dependency>
        <groupId>com.atlassian.plugin</groupId>
        <artifactId>atlassian-spring-scanner-runtime</artifactId>
        <version>${atlassian.spring.scanner.version}</version>
        <scope>runtime</scope>
    </dependency>
    
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
        <scope>provided</scope>
    </dependency>
    
    <dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>javax.servlet-api</artifactId>
		<version>4.0.0-b07</version>
		<scope>provided</scope>
	</dependency>
	
	<dependency>
	    <groupId>com.atlassian.plugins.rest</groupId>
	    <artifactId>atlassian-rest-common</artifactId>
	    <version>2.8.2</version>
	    <scope>provided</scope>
	</dependency>
	
	<!-- plugin-manager dependencies -->
	<dependency>
	    <groupId>com.atlassian.upm</groupId>
	    <artifactId>licensing-api</artifactId>
	    <version>2.21.4</version>
	    <scope>provided</scope>
	</dependency>
	<dependency>
	    <groupId>com.atlassian.upm</groupId>
	    <artifactId>upm-api</artifactId>
	    <version>2.21</version>
	    <scope>provided</scope>
	</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.2-atlassian-1</version>
        <scope>provided</scope>
    </dependency>-->
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-confluence-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>

                <!-- See here for an explanation of default instructions: -->
                <!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
                <instructions>
                    <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

                    <!-- Add package to export here -->
                    <Export-Package>
                    </Export-Package>

                    <!-- Add package import here -->
                    <Import-Package>
                        org.springframework.osgi.*;resolution:="optional",
                        org.eclipse.gemini.blueprint.*;resolution:="optional",
                        *
                    </Import-Package>

                    <!-- Ensure plugin is spring powered -->
                    <Spring-Context>*</Spring-Context>
                </instructions>
            </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>
                    <phase>process-classes</phase>
                </execution>
            </executions>
            <configuration>
                <scannedDependencies>
                    <dependency>
                        <groupId>com.atlassian.plugin</groupId>
                        <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                    </dependency>
                </scannedDependencies>
                <verbose>false</verbose>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
    <finalName>smart-qa-${version}</finalName>
</build>

<properties>
    <confluence.version>5.10.7</confluence.version>
    <confluence.data.version>5.10.5</confluence.data.version>
    <amps.version>6.2.11</amps.version>
    <plugin.testrunner.version>1.2.3</plugin.testrunner.version>
    <atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
    <!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. -->
    <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
</properties>

<version>2.0.0</version>
<name>Smart Questions and Answers</name>
<url>https://bitbucket.org/apurde/simple-qa/wiki</url>

Are you using the @Named() annotation to declare the SimpleQAHelper bean? I can’t see the first line of the class.

Yes I do use @Named.

What is the full import statement for MailServerManager?

import com.atlassian.mail.server.MailServerManager;

In the pom.xm - in the Import-Package make sure to include ‘com.atlassian.mail.server.*’ (comma deliminated).

1 Like

Hi Daniel. This does not not help unfortunately.

@andreas1 try to make

<Import-Package>
                        org.springframework.osgi.*;resolution:="optional",
                        org.eclipse.gemini.blueprint.*;resolution:="optional",
                        *;resolution:="optional" 
</Import-Package>

I guess you are trying build plugin with version 2, this https://bitbucket.org/atlassian/atlassian-spring-scanner/src/master/ will be helpful

Dear @nturchin. Thank you for your suggestion. However it does not help. Honestly I doubt that it is an import problem as all the other injects are working without any problems. In my case it is only the MailServerManager which causes trouble.

@andreas1 I’ll try to reproduce your problem today, and let you know.

Problem is not in MailServerManager, it’s in PluginLicenseManager, something going wrong with class loading when these dependencies declared together. I guess problem in nested dependencies, some conflicts.
At this moment I don’t have any ideas with solution.

Dear @nturchin. Thank you very much for trying.

Hi @andreas1 & @nturchin,

Did you manage to find a solution to this? I am also hitting into the same issue. The UPM and MailServerManager do not want to play well.

Hi @tchin, I found just only one solution, MailFactory.getServerManager().

Hi @nturchin,

Thank you very much for that. Code works using the MailFactory.

@tchin You’re welcome. Be careful, the mail server object can be null if it has not been configured.

Right. Not my fault if they did not configure a smtp server where the functionality and documentation clearly states and relies on one.

:joy: