How do I inject JIRA component into Rest module using Spring Scanner method?

DanielG
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2016

I'm trying to inject com.atlassian.jira.user.UserUtils into a REST module type.

I've tried to follow the instructions at https://bitbucket.org/atlassian/atlassian-spring-scanner to no avail.

Here is the code for the module:

@Scanned
@Path("/search")
public class EmailToNameRest {
    private final UserUtils userUtils;
    @Autowired
	public EmailToNameRest(@ComponentImport UserUtils userUtils) {
        this.userUtils = userUtils;
    }
    @GET
    @AnonymousAllowed
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response getMessage()
    {
        final ApplicationUser user = userUtils.getUser("admin@exmaple.com");
        return Response.ok(new EmailToNameRestModel(user.getDisplayName())).build();
    }
}

When I try and run the module I get either:

[c.a.p.osgi.factory.OsgiPlugin] Detected an error (BundleException) enabling the plugin 'com.wikistrat.jira.emaillogin' : Unresolved constraint in bundle com.wikistrat.jira.emaillogin [177]: Unable to resolve 177.0: missing requirement [177.0] osgi.wiring.package; (osgi.wiring.package=com.atlassian.jira.user.UserUtils).

or

com.wikistrat.jira.emaillogin' - 'emaillogin'  failed to load.
The plugin has been disabled.  A likely cause is that it timed out during initialisation
It has the following missing service dependencies : &userUtils of type (&(objectClass=com.atlassian.jira.user.UserUtils)(objectClass=com.atlassian.jira.user.UserUtils))

But I am declaring these items in my pom.xml

<build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-jira-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>
                    <enableFastdev>false</enableFastdev>
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <!-- Add package to export here -->
                        <Export-Package>com.wikistrat.jira.api,</Export-Package>
                        <!-- Add package import here -->
                        <Import-Package>
                            org.springframework.osgi.*;resolution:="optional",
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            com.atlassian.jira.user,
                            com.atlassian.jira.user.UserUtils,
                            com.atlassian.jira.*;resolution:="optional",
                            *
                        </Import-Package>
                        <Spring-Context>*</Spring-Context>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

I've tried using other annotations like @Component instead of @Scanned but it doesn't seem to help.

I've posted the repo at https://bitbucket.org/wsdan/jira-spring-scanner-nolove if someone wants to see the full code.

Any suggestions?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Jon Mort [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2016

The root cause of this is that UserUtils is not a component to inject. Try using UserManager.

 

You probably want to check your Import-Package too. It should not contain any classes, and if you use *, you shouldn't need to include any packages that you use directly.

To help debug these things you can enable verbose output from the spring scanner maven plugin.

DanielG
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2016

You're correct, turns out the issue was that I was trying to import a static class that was in turn relying on UserManager.

TAGS
AUG Leaders

Atlassian Community Events