Active Objects injection for db transaction not enabled on Custom made Jira Plugins

Hi,

Here is an issue I am facing why injecting Active Objects(com.atlassian.activeobjects.external.ActiveObjects) in my servlet class that extends javax.servlet.http.HttpServlet;

Here are the possible ways I have tried to inject the Active Objects:

@Inject public CustomPluginServlet(@ComponentImport ActiveObjects activeObjects){
this.activeObjects = activeObjects
}

Option 2:
public CustomPluginServlet(){
this.activeObjects = ComponentAccessor.getOSGiComponentInstanceOfType(ActiveObjects.class);
}

Option 3:
public CustomPluginServlet(){
this.activeObjects = ComponentAccessor.getComponent(ActiveObjects.class);
}

Option 4:
public CustomPluginServlet(){
this.activeObjects = ComponentLlcator.getComponent(ActiveObjects.class);
}

Here is the stacktrace that is generated once the plugin tries to innject the ActiveObjects dependency:

java.lang.IllegalStateException: plugin [{org.apache.felix.framework}] invoking ActiveObjects before configuration module is enabled or plugin is missing an configuration module. Note that scanning of entities from the ao.model package is no longer supported.

This error appears even after the ao config is present in the atlassian-plugin.xml.
<ao key="ao-module"> <description>The module configuring the Active Objects service used by this plugin</description> <entity>com.xxxx.xxx.xx.applications.model.CustomPluginEntity</entity> </ao>

Is there a solution for this, any alternative? because the ActiveObjects provide ORM support to to the custom plugin which would be needed to save retrieve data. Any help is highly appreciated. Thanks!

Hi @RaviSaurav,

I tested and was able to inject ActiveObjects into a Servlet using Atlassian Spring Scanner. Specifically, I was able to use the following formats:

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.google.common.base.Preconditions;

@ComponentImport
final ActiveObjects ao;

public MyServlet(ActiveObjects ao) {
    this.ao = Preconditions.checkNotNull(ao);
}
final ActiveObjects ao;

public MyServlet(@ComponentImport ActiveObjects ao) {
    this.ao = Preconditions.checkNotNull(ao);
}

The first pattern is listed on: DAC: Getting started with Active Objects.

Troubleshooting

Given that you’ve already followed the second pattern, I would ensure your Maven and Spring configurations are set correctly.

Maven POM

<dependencies>
	<dependency>
		<groupId>com.atlassian.jira</groupId>
		<artifactId>jira-api</artifactId>
		<version>${jira.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>provided</scope>
	</dependency>
	<dependency>
		<groupId>com.atlassian.activeobjects</groupId>
		<artifactId>activeobjects-plugin</artifactId>
		<version>${ao.version}</version>
		<scope>provided</scope>
	</dependency>
</dependencies>
...
<build>
    ...
	<plugins>
		<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>
				<verbose>false</verbose>
			</configuration>
		</plugin>
	</plugins>
</build>
...
<jira.version>10.3.11</jira.version>
<!-- Version bundled with DC Platform 7.2 for Jira 10.3 -->
<atlassian.spring.scanner.version>5.1.0</atlassian.spring.scanner.version>
<!-- Version bundled with DC Platform 7.2 for Jira 10.3 -->
<ao.version>6.1.2</ao.version>
...
<build>
    ...
	<plugins>
		<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>
				<verbose>false</verbose>
			</configuration>
		</plugin>
	</plugins>
</build>
...
<jira.version>10.3.11</jira.version>
<!-- Version bundled with DC Platform 7.2 for Jira 10.3 -->
<atlassian.spring.scanner.version>5.1.0</atlassian.spring.scanner.version>
<!-- Version bundled with DC Platform 7.2 for Jira 10.3 -->
<ao.version>6.1.2</ao.version>

Spring context

Should match the snippet at atlassian-spring-scanner exactly (check version!).

ActiveObjects registry

Does your AO entity appear at :gear: (gear icon) > System > Plugin data storage? If not, that would indicate a problem with your usage of ActiveObjects, not dependency injection.

- Ben, Atlassian DC Support

Hi Ben, Thanks for your response, I have tried the suggestion you gave still the below error looms stating the injection did not happen.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.xxxx.xxx.xx.xxxxxxxx.servlet.MyPluginServlet’: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.atlassian.activeobjects.external.ActiveObjects’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:

Here is my servlet code:

@Named
public class MyPluginServlet extends HttpServlet {
    private static final Logger log = LoggerFactory.getLogger(MyPluginServlet class);

    private final ActiveObjects activeObjects;

    @Inject
    public MyPluginServlet(@ComponentImport ActiveObjects activeObjects){
        this.activeObjects = Preconditions.checkNotNull(activeObjects);
    }

….other code
}

Here is the config as you suggested:

        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.google.code.gson</groupId>
                    <artifactId>gson</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
<dependency>
    <groupId>com.atlassian.plugin</groupId>
    <artifactId>atlassian-spring-scanner-annotation</artifactId>
    <version>5.1.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.atlassian.activeobjects</groupId>
    <artifactId>activeobjects-plugin</artifactId>
    <version>6.1.2</version>
    <scope>provided</scope>
</dependency>
<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>
       <verbose>false</verbose>
    </configuration>
</plugin>

Also I can see my entities under :gear: (gear icon) > System > Plugin data storage.

Let me know if I am missing something here. Thanks!