春季-在自定义Atlassian JIRA插件中注入SoyTemplateRenderer

我目前正在尝试开发自定义的Jira插件,该插件还使用servlet渲染Soy模板.

这是我的servlet的代码:

    /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package at.fraiss.plugins.custommenuitem.servlets;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.atlassian.soy.renderer.SoyTemplateRenderer;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Mario
 */
public class SoyTemplateServlet extends HttpServlet {

    private SoyTemplateRenderer soyTemplateRenderer;

    public SoyTemplateServlet(SoyTemplateRenderer soyTemplateRenderer)
    {
        this.soyTemplateRenderer = soyTemplateRenderer;
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        response.setContentType("text/html");
        response.getWriter().write(getHtml());
    }

    public String getHtml()
    {
        Map<String, Object> data = new HashMap<String,Object>();
        data.put("isLocal", true);
        data.put("url", "http://www.example.com");
        data.put("title", "example");
        return this.soyTemplateRenderer.render("jira.webresources:soy-templates", "JIRA.Templates.Links.helpLink", data);
    }
}

这是我在atlassian-plugin.xml描述符中定义大豆模板文件的方式:

<web-resource key="soy-templates">
    <dependency>com.atlassian.soy.soy-template-plugin:soy-deps</dependency>


    <!-- Available to the server-side only -->
    <resource type="soy" name="links" location="links.soy"/>
 
    <!-- Make available to the client-side in JS as well... -->
    <transformation extension="soy">
        <transformer key="soyTransformer"/>
    </transformation>
    <resource type="download" name="Links.soy.js" location="links.soy"/>
</web-resource>

我在pom.xml中添加了以下部分:

<dependency>
        <groupId>com.atlassian.soy</groupId>
        <artifactId>soy-template-renderer-api</artifactId>
        <version>4.0.4</version>
        <scope>provided</scope>
    </dependency>

尝试访问servlet时总是会收到此错误

[INFO] [talledLocalContainer]原因:org.springframework.beans.factory.Unsat isfiedDependencyException:创建名称为“ at.fraiss.plugins.cust ommenuitem.servlets.SoyTemplateServlet”的bean时出错:通过带有索引0的构造函数参数表示的不满意依赖项类型为[com.atlassian.soy.renderer.SoyTempl ateRenderer]的类型::找不到依赖项为类型为[com.atlassian.soy.renderer.SoyTempla teRenderer]的合​​格bean:期望至少有1个bean符合此条件的自动候选依赖性.依赖注释:{};嵌套的excepti上是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有发现类型为[com.atlassian.soy.renderer.SoyTemplateRenderer]的合​​格Bean,其Dep持久性:期望至少有1个Bean符合此依赖项的自动装配候选条件.依赖注释:org.springframework.beans.factory.support.Con上的{} [INFO] [talledLocalContainer] structorResolver.createArgumentArray(ConstructorResolver.java:749)[org] org.springframework.beans.beans.factory.support上的[INFO] [talledLocalContainer]. ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)[信息] [talledLocalContainer]在org.springframework.beans.factory.support.Abs tractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanF actory.java:1139)[INFO] [talledLocalContainer] .beans.factory.support.Abs tractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFa ctory.java:1042)[INFO] [talledLocalContainer],位于org.springframework.beans.factory.support.Abs tractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory] ​​[java:504) [talledLocalContainer],位于org.springframework.beans.factory.support.Abs tractAutowireCapableBeanFactory.createBean(AbstractAutowireCapabl eBeanFactory.ja va:342)[INFO] [talledLocalContainer] … 2在java.lang.reflect.Method.invoke(Method.java:4 97)过滤了[INFO] [talledLocalContainer] [com]在com上的[INFO] [talledLocalContainer] .atlassian.plugin.osgi.spring.DefaultSprin gContainerAccessor.createBean(DefaultSpringContainerAccessor.java:112)[INFO] [talledLocalContainer],位于com.atlassian.plugin.module.ClassPrefixModule Factory.createModule(ClassPrefixModuleFactory.java:39)[INFO] [ com.atlassian.plugin.module.PrefixDelegatingM上的talledLocalContainer] oduleFactory.createModule(PrefixDelegatingModuleFactory.java:100)com.atlassian.plugin.servlet.descriptors.Serv letModuleDescriptor.getModule(Servlet:ModuleDescriptor.com)上的[INFO] [talledLocalContainer] com.atlassian.plugin.servlet.DelegatingPlugin Servlet上的[INFO] [talledLocalContainer]. 最佳答案

我也遇到了这个问题(并且浪费了很多时间).

Spring扫描器显然仅处理标记有@Named的类.

这对我有用:

@Named("MyServlet")
public class MyServlet extends HttpServlet{
    @ComponentImport
    private final SoyTemplateRenderer soyTemplateRenderer;

    @Inject
    public MyServlet(@ComponentImport final SoyTemplateRenderer soyTemplateRenderer) {
        this.soyTemplateRenderer = soyTemplateRenderer;
    }
}

相关文章

点击查看更多相关文章

转载注明原文:春季-在自定义Atlassian JIRA插件中注入SoyTemplateRenderer - 代码日志

>(delegatingpluginservlet.java:33)com.atlassian.plugin.servlet.defaultservletmo上的[info]>

解决方法:

我也遇到了这个问题(并且浪费了很多时间).

Spring扫描器显然仅处理标记有@Named的类.

这对我有用:

@Named("MyServlet")
public class MyServlet extends HttpServlet{
    @ComponentImport
    private final SoyTemplateRenderer soyTemplateRenderer;

    @Inject
    public MyServlet(@ComponentImport final SoyTemplateRenderer soyTemplateRenderer) {
        this.soyTemplateRenderer = soyTemplateRenderer;
    }
}
上一篇:更新选择列表自定义字段-Jira Python


下一篇:java-检查是否存在Jira问题列表