TemplateRenderer can not be inject

this is my code:

@Scanned
public class Login extends HttpServlet {
private static final Logger log = LoggerFactory.getLogger(Login.class);
@ComponentImport
private TemplateRenderer templateRenderer;
@ComponentImport
private ProjectService projectService;

@Inject
public Login(ProjectService projectService,TemplateRenderer templateRenderer) {
	this.projectService = projectService;
	this.templateRenderer = templateRenderer;
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	TemplateRenderer templateRenderer = ComponentAccessor.getComponent(TemplateRenderer.class);
	System.out.println("myClass=" + templateRenderer);
	System.out.println("projectService=" + projectService);
	resp.setContentType("text/html");
	resp.getWriter().write("<html><body>Hello World</body></html>");
}

public TemplateRenderer getTemplateRenderer() {
	return templateRenderer;
}

public void setTemplateRenderer(TemplateRenderer templateRenderer) {
	this.templateRenderer = templateRenderer;
}

}

my dependency is:

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

and the result is:
[INFO] [talledLocalContainer] myClass=null
[INFO] [talledLocalContainer] projectService=com.atlassian.jira.bc.project.DefaultProjectService@58dfd746

I seams the ProjectService can be inject to the class,but the TemplateRenderer can’t. can I use TemplateRenderer in jira plugin?My jira version is 7.3.2,and sdk version is 6.3.13.

Anyone can help?Thanks a lot!

I resolve it myself, just make a little mistake,it doesn’t need the code:
TemplateRenderer templateRenderer = ComponentAccessor.getComponent(TemplateRenderer.class);

thanks a lot!

Hi,

it also should work based on your first approach. Normally injecting the TemplateRenderer in Jira using the SpringScanner approach should work. And you should prefer it over the Component Accessor approach. On first look, your code looks correct. You can check whether or not you have any Spring Scanner related error messages in the log when installing the plugin.

Kind regards,
Alexander

1 Like

Thank you for your advice!

Hi!, I’m a begginer developing with Atlassian SDK and I’m following the tutorial provided on Atlassian SDK Developer, but I’m stucked here https://developer.atlassian.com/server/framework/atlassian-sdk/create-a-gui-with-templates-and-aui/ trying to add a velocity template because it requires the class TemplateRenderer to be imported, BUT Eclipse doesn’t seems to find it. I tryed looking for that particular library without any luck.

Is there a way to create a template or a GUI interface without using this library?. How?.

Thanks a lot.

http://mvnrepository.com/search?q=com.atlassian.templaterenderer

you can find the library at maven repository

1 Like

Thanks a lot for your answer. I also found it here https://bitbucket.org/atlassian/atlassian-template-renderer/downloads/ . :grin: