It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Cant import ProjectService.

Joel Suter Sep 04, 2017

Everytime i try to import the ProjectService it gives me a excepiton. 

But everytime i import the UserService it works perfectly fine. What is the problem here? I use the new version of the plugin/spring so it should take care of the imports as long as i annotate them. Can someone tell me what i am doing wrong, and please give me a full example? I already looked everywhere The code for the ProjectService import looks like this: 

@Path("/message")
@Scanned
public class ProjectResource {

private ProjectService projectService;

@Autowired
public ProjectResource(@ComponentImport ProjectService projectService){
this.projectService = projectService;
}

@GET
@AnonymousAllowed
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getMessage()
{
return Response.ok(new ProjectResourceModel("Hello World")).build();
}

 

d

 

1 answer

1 accepted

0 votes
Answer accepted
MoroSystems Support Sep 04, 2017

I have two suggestions:

  • once I experienced such problem when I forgot to use <scope>provided</scope> on one dependency in pom.xml
  • another solution which always come on my mind is to shut down your environment, clean caches:
    • JIRA_HOME/plugins/.bundled-plugins
    • JIRA_HOME/plugins/.osgi-plugins

If you're using spring scanner 2.x, you can check imports file in /META-INF/plugin-components/ inside your *.jar file. If entry for com.atlassian.jira.bc.project.ProjectService is in there, I think cleanin caches will be enough.

BTW, you don't need to use @Scanned annotation if you're on Spring Scanner 2.x.

There is also Troubleshooting section on page with spring scanner documentation: https://bitbucket.org/atlassian/atlassian-spring-scanner

Joel Suter Sep 05, 2017

Okey my plugin doesn't import the services in the plugin-components inside my jar. If i do it manually it works but if I reload it it will kick out the import and it stops working.

How can I make sure that it imports them automatically.

MoroSystems Support Sep 05, 2017

Did you check troubleshooting section in linked document? What version of spring scanner are you using? Can you post your pom.xml file?

Joel Suter Sep 05, 2017

yes i checked, its now almost working. Sometimes i have to manually import a service and sometimes i dont. I should have version 2 of spring scanner.

Pom:

<?xml version="1.0" encoding="UTF-8"?>

-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">

<modelVersion>4.0.0</modelVersion>

<groupId>com.zuehlke.ams.pss</groupId>

<artifactId>monitor.bitbucket2</artifactId>

<version>1.0.0-SNAPSHOT</version>


-<organization>

<name>Example Company</name>

<url>http://www.example.com/</url>

</organization>

<name>monitor.bitbucket2</name>

<description>This is the com.zuehlke.ams.pss:monitor.bitbucket2 plugin for Atlassian Bitbucket Server.</description>

<packaging>atlassian-plugin</packaging>


-<dependencyManagement>


-<dependencies>


-<dependency>

<groupId>com.atlassian.bitbucket.server</groupId>

<artifactId>bitbucket-parent</artifactId>

<version>${bitbucket.version}</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>


-<dependencies>


-<dependency>

<groupId>com.atlassian.sal</groupId>

<artifactId>sal-api</artifactId>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>com.atlassian.bitbucket.server</groupId>

<artifactId>bitbucket-api</artifactId>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>com.atlassian.bitbucket.server</groupId>

<artifactId>bitbucket-spi</artifactId>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>com.atlassian.bitbucket.server</groupId>

<artifactId>bitbucket-page-objects</artifactId>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.10</version>

<scope>test</scope>

</dependency>


-<dependency>

<groupId>commons-lang</groupId>

<artifactId>commons-lang</artifactId>

<version>2.6</version>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>com.atlassian.plugin</groupId>

<artifactId>atlassian-spring-scanner-annotation</artifactId>

<version>${atlassian.spring.scanner.version}</version>

<scope>compile</scope>

</dependency>


-<dependency>

<groupId>com.atlassian.plugin</groupId>

<artifactId>atlassian-spring-scanner-runtime</artifactId>

<version>${atlassian.spring.scanner.version}</version>

<scope>runtime</scope>

</dependency>


-<dependency>

<groupId>javax.inject</groupId>

<artifactId>javax.inject</artifactId>

<version>1</version>

<scope>provided</scope>

</dependency>

<!-- WIRED TEST RUNNER DEPENDENCIES -->

 

-<dependency>

<groupId>com.atlassian.plugins</groupId>

<artifactId>atlassian-plugins-osgi-testrunner</artifactId>

<version>${plugin.testrunner.version}</version>

<scope>test</scope>

</dependency>


-<dependency>

<groupId>javax.ws.rs</groupId>

<artifactId>jsr311-api</artifactId>

<version>1.1.1</version>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>com.google.code.gson</groupId>

<artifactId>gson</artifactId>

<version>2.2.2-atlassian-1</version>

</dependency>


-<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>2.4</version>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>javax.xml.bind</groupId>

<artifactId>jaxb-api</artifactId>

<version>2.1</version>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>com.atlassian.plugins.rest</groupId>

<artifactId>atlassian-rest-common</artifactId>

<version>1.0.2</version>

<scope>provided</scope>

</dependency>


-<dependency>

<groupId>org.apache.wink</groupId>

<artifactId>wink-client</artifactId>

<version>1.1.3-incubating</version>

<scope>test</scope>

</dependency>


-<dependency>

<groupId>org.mockito</groupId>

<artifactId>mockito-all</artifactId>

<version>1.8.5</version>

<scope>test</scope>

</dependency>

</dependencies>


-<build>


-<plugins>


-<plugin>

<groupId>com.atlassian.maven.plugins</groupId>

<artifactId>bitbucket-maven-plugin</artifactId>

<version>${amps.version}</version>

<extensions>true</extensions>


-<configuration>


-<products>


-<product>

<id>bitbucket</id>

<instanceId>bitbucket</instanceId>

<version>${bitbucket.version}</version>

<dataVersion>${bitbucket.data.version}</dataVersion>

</product>

</products>


-<instructions>

<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

<!-- Add package to export here -->


<Export-Package>com.zuehlke.ams.pss.api,</Export-Package>

<!-- Add package import here -->


<Import-Package>org.springframework.osgi.*;resolution:="optional", org.eclipse.gemini.blueprint.*;resolution:="optional", *</Import-Package>

<!-- Ensure plugin is Spring powered -->


<Spring-Context>*</Spring-Context>

</instructions>

</configuration>

</plugin>


-<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>

</plugins>

</build>


-<properties>

<bitbucket.version>4.9.1</bitbucket.version>

<bitbucket.data.version>4.9.1</bitbucket.data.version>

<amps.version>6.2.11</amps.version>

<plugin.testrunner.version>1.2.3</plugin.testrunner.version>

<atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>

<!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. -->


<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>

</properties>

</project>

MoroSystems Support Sep 05, 2017 • edited

You're using spring scanner in version 1.2.13 (<atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>). Try to change:

<Import-Package>org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional", *</Import-Package>

to:

<Import-Package>org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",*;resolution:=optional</Import-Package>

 If you're developing plugin for Bitbucket Server 5.0+, you can branch your plugin and try to use Spring Scanner 2.x

Joel Suter Sep 05, 2017

Thank you so much for your help. I dont know what did it but for now it works. Thanks for the clear instructions, i am very new to all of this.

If you have time could you look into another issue that I ran into?

https://community.atlassian.com/t5/Bitbucket-questions/How-to-make-a-GET-request-on-Bitbucket-plugin-rest-api/qaq-p/635166#M18942

Thank you so much. <3

MoroSystems Support Sep 05, 2017

Sure, I will check it, but please accept my answer if it did help you with your ProjectService issue.

Joel Suter Sep 05, 2017

Ah of course, sorry forgot to. Of course.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

3,092 views 1 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you