TemplateRenderer available: expected at least 1 bean which qualifies as autowire candidate

hello,

Could you please help me, I have the following error when trying to see the link of my plugin in atlassian:

compiles and builds the jar correctly, installs the plugin in attlassian fine,
but when wanting to enter the link that it generates in the menu, it sends that error in the log and on the screen a 404

org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1685)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.atlassian.templaterenderer.TemplateRenderer' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport(value="")}

Jira SDK 8.2.7
Java version 1.8

Code Servlet:

package com.baufest.feedback.servlet;

import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.templaterenderer.TemplateRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.baufest.feedback.service.interfaces.GlobalConfigurationService;

import javax.inject.Named;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Named("ConfiguracionServlet")
public class ConfiguracionServlet extends HttpServlet{
    private static final Logger log = LoggerFactory.getLogger(ConfiguracionServlet.class);
    private final TemplateRenderer render;
    private final GlobalConfigurationService globalConfigurationService;

    @Autowired
    public ConfiguracionServlet(@ComponentImport TemplateRenderer render, final GlobalConfigurationService globalConfigurationService){
        this.render=render;
        this.globalConfigurationService = globalConfigurationService;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        this.render.render("templates/configuracion/configuracion-feedback-url.vm", mapContext(), resp.getWriter());
    }

    private Map<String, Object> mapContext() {
        Map<String, Object> context = new HashMap<>();
        context.put("urlText", this.globalConfigurationService.getUrlText());
        return context;
    }


}

Code GlobalConfigurationServiceImpl

package com.baufest.feedback.service.impl;

import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.sal.api.pluginsettings.PluginSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.baufest.feedback.service.interfaces.GlobalConfigurationService;


public class GlobalConfigurationServiceImpl implements GlobalConfigurationService {

    private final PluginSettingsFactory pluginSettingsFactory;

    @Autowired
    public GlobalConfigurationServiceImpl(@ComponentImport PluginSettingsFactory pluginSettingsFactory) {
        this.pluginSettingsFactory = pluginSettingsFactory;
    }

    @Override
    public String getUrlText() {
        return parseValueToString("urlText");
    }

    private String parseValueToString(String key) {
        Object fieldObject = obtenerValor(key);
        return (fieldObject == null) ? "" : fieldObject.toString();
    }

    private Object obtenerValor(String key) {
        PluginSettings pluginSettings = this.pluginSettingsFactory.createGlobalSettings();
        return pluginSettings.get(key);
    }
}

atlassian-plugin.xml

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

<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2"> 
  <plugin-info> 
    <description>${project.description}</description>  
    <version>${project.version}</version>  
    <vendor name="${project.organization.name}" url="${project.organization.url}"/>  
    <param name="plugin-icon">images/pluginIcon.png</param>  
    <param name="plugin-logo">images/pluginLogo.png</param> 
  </plugin-info>  
  <!-- add our i18n resource -->  
  <resource type="i18n" name="i18n" location="feedback"/>  
  <!-- add our web resources -->  
  <web-resource key="feedback-resources" name="feedback Web Resources"> 
    <dependency>com.atlassian.auiplugin:ajs</dependency>  
    <resource type="download" name="feedback.css" location="/css/feedback.css"/>  
    <resource type="download" name="feedback.js" location="/js/feedback.js"/>  
    <resource type="download" name="images/" location="/images"/>  
    <context>feedback</context>  
    <context>jira.general</context>  
    <context>jira.popup</context>  
    <context>jira.userprofile</context>  
    <context>jira.dashboard</context>  
    <context>jira.browse</context>  
    <context>jira.browse.component</context>  
    <context>jira.browse.project</context>  
    <context>jira.browse.projects</context>  
    <context>jira.browse.version</context>  
    <context>jira.view.issue</context>  
    <context>jira.create.issue</context>  
    <context>jira.navigator.advanced</context>  
    <context>jira.navigator.simple</context>  
    <context>jira.admin</context>  
    <context>jira.error</context> 
  </web-resource>  

  <servlet name="Configuracion Servlet" i18n-name-key="configuracion-servlet.name" key="configuracion-servlet" class="com.baufest.feedback.servlet.ConfiguracionServlet">
    <description key="configuracion-servlet.description">The Feedback Jira Plugin</description>
    <url-pattern>/configuracionservlet</url-pattern> 
  </servlet>  
  <web-section name="Confluence Global" i18n-name-key="confluence-global.name" key="confluence-global" location="admin_plugins_menu" weight="1000"> 
    <description key="confluence-global.description">The Confluence Global Plugin</description>  
    <label key="confluence-global.label"/> 
  </web-section>  
  <web-item name="ServletConfiguration" i18n-name-key="servlet-configuration.name" key="servlet-configuration" section="admin_plugins_menu/confluence-global" weight="1000">
    <description key="servlet-configuration.description">The ServletConfiguration Plugin</description>
    <label key="servlet-configuration.label"/>
    <link linkId="servlet-configuration-link">/plugins/servlet/configuracionservlet</link>
  </web-item>  
</atlassian-plugin>

POM:

<?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>
    <groupId>com.baufest</groupId>
    <artifactId>feedback</artifactId>
    <version>1.1.0</version>
    <organization>
        <name>Example Company</name>
        <url>http://www.example.com/</url>
    </organization>
    <name>feedback</name>
    <description>This is the com.baufest:feedback plugin for Atlassian JIRA.</description>
    <packaging>atlassian-plugin</packaging>
    <dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        <!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
        <!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
        <!--
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</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>
        <!-- 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>
        </dependency>
        <!-- Uncomment to use TestKit in your project. Details at https://bitbucket.org/atlassian/jira-testkit -->
        <!-- You can read more about TestKit at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Smarter+integration+testing+with+TestKit -->
        <!--
        <dependency>
            <groupId>com.atlassian.jira.tests</groupId>
            <artifactId>jira-testkit-client</artifactId>
            <version>${testkit.version}</version>
            <scope>test</scope>
        </dependency>
        -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.1.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.templaterenderer</groupId>
            <artifactId>atlassian-template-renderer-api</artifactId>
            <version>LATEST</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>2.5.6.SEC02</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>jira-maven-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.version}</productDataVersion>
                    <!-- Uncomment to install TestKit backdoor in JIRA. -->
                    <!--
                    <pluginArtifacts>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.tests</groupId>
                            <artifactId>jira-testkit-plugin</artifactId>
                            <version>${testkit.version}</version>
                        </pluginArtifact>
                    </pluginArtifacts>
                    -->
                    <enableQuickReload>true</enableQuickReload>
                    <!-- 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>com.baufest.feedback.api,</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>
                    <!-- Enable this to get build-time logging of annotations atlassian-spring-scanner-maven-plugin has noticed -->
                    <verbose>false</verbose>

                    <!-- EXAMPLE EXAMPLE EXAMPLE :)
                         Demonstrates excluding packages from scanning, and scanning an example dependency jar.
                         Please see the docs below. -->

                    <includeExclude>+com.atlassian.jira.plugins.issue.create.*</includeExclude>
                    <scannedDependencies>
                        <dependency>
                            <groupId>com.atlassian.plugin</groupId>
                            <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                        </dependency>
                    </scannedDependencies>
                    <verbose>false</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <jira.version>8.20.1</jira.version>
        <amps.version>8.0.2</amps.version>
        <plugin.testrunner.version>2.0.1</plugin.testrunner.version>
 <atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
        <!-- This property ensures consistency between the key in atlassian-plugin.xml and the OSGi bundle's key. -->
        <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
        <!-- TestKit version 6.x for JIRA 6.x -->
        <testkit.version>6.3.11</testkit.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

Thanks for your help

1 Like

Resuelto

how to resuelto