I always got the IssueManager the following way:
ComponentAccessor.getIssueManager()
Now in my friend's code I saw another way:
@JiraImport
private IssueManager issueManager;
So is there any difference in the 2 approaches ? What is better ? I really liked using ComponentAccessor.
In general I find it quite interesting that there are always at least 2 ways to get a specific object. For example to get the attachments of an issue , you can get it from issue itself all via the AttachmentManager.
Hi @Albert Cameron the second way is clearer as it uses dependency injection principle of OSGi framework which is used by Jira (https://dzone.com/articles/osgi-dependency-injection). So I really suggest you to use @JiraImport annotation :)
More information about annotations, OSGi and Spring Scanner is here: https://bitbucket.org/atlassian/atlassian-spring-scanner/src/master/
public class MyClassextends AbstractJiraFunctionProvider
{
private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
@JiraImport
private WorkflowManager workflowManager;
@JiraImport
private JiraAuthenticationContext authenficationContext;
@JiraImport
private IssueManager issueManager;
@JiraImport
private AttachmentManager attachmentManager;
In this case all the @JiraImport annotations were not working. All the objects were null. So I had to use ComponentAccessor. Am I missing an annotation above the class. Is the class not registered as a possible bean ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you check what spring-scanner dependencies do you use in your pom.xml file? It should be something like:
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>provided</scope>
</dependency>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>provided</scope>
</dependency>
<atlassian.spring.scanner.version>2.0.0</atlassian.spring.scanner.version>
and also I use this:
<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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I'm using version 2.1.3 on one of our older projects. First question is, what version of Jira do you use?
I found one postfuncion which uses @Autowired annotation on constructor and it looks like
import com.atlassian.jira.workflow.WorkflowManager;
import com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.WorkflowException;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Map;
public class ApprovalPostFunction extends AbstractJiraFunctionProvider {
private final WorkflowManager workflowManager;
@Autowired
public ApprovalPostFunction(@ComponentImport final WorkflowManager workflowManager) {
this.workflowManager = workflowManager;
}
@Override
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
// execute function here
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We are using Jira V8.8.1.
@JiraImport should really work. I do not wanna do Constructor Injection
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Albert Cameron , I just found some Atlassian examples and they are using constructor injection:
I'm not sure if it is not necessary for classes which extend something because you describe constructor which should be used for dependency injection. Could you at least give it a try?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok thanks. Maybe it is more important to have an annotation above the class
issuecrud/IssueCRUD.java at master · loganrobertclemons/issuecrud · GitHub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scanned annotation is not used for SpringScanner 2.x.x
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.