如何在SpringBoot中自动装配/注入JIRAs CustomFieldManager / ComponentAccessor?

时间:2018-02-03 21:45:49

标签: spring-boot dependency-injection jira autowired

我正在使用JIRA 7.1.6并始终获得异常

  

没有合格的bean类型   ' com.atlassian.jira.issue.CustomFieldManager'可用...

尝试在SpringBoot应用程序中注释我的服务中的CustomFieldManager属性时。当我尝试使用ComponentAccessor时会发生同样的情况。

我该如何解决这个问题?

与此同时,我发现尽管使用CustomFieldManager,仍应使用ComponentAccessor:

CustomFieldManager cfm = ComponentAccessor.getComponent(CustomFieldManager.class);
CustomField cf = cfm.getCustomFieldObjectByName(k); 

...但我得到了同样的例外。

这是POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                         http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.xxxxx</groupId>
<artifactId>zzzz</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>TheApp</name>
<url>http://maven.apache.org</url>

<!-- Inherit defaults from Spring Boot -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
    <jira.version>7.1.6</jira.version>
    <org.mapstruct.version>1.2.0.Final</org.mapstruct.version>
    <maven-jaxb2-plugin.version>0.13.3</maven-jaxb2-plugin.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <!-- <version>2.26</version> -->
    </dependency>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-api</artifactId>
        <version>4.0.0</version>
        <!-- <scope>provided</scope> -->
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-api</artifactId>
        <version>${jira.version}</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>jta</groupId>
                <artifactId>jta</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- <dependency> <groupId>com.atlassian.fugue</groupId> <artifactId>fugue</artifactId> 
        <version>2.6.1</version> <scope>provided</scope> </dependency> -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <!-- <version>1.5.9.RELEASE</version> -->
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
        <!-- <version>1.5.9.RELEASE</version> -->
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <!-- <version>1.5.9.RELEASE</version> -->
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-jersey2-jaxrs</artifactId>
        <version>1.5.17</version>
    </dependency>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-jdk8</artifactId>
        <version>${org.mapstruct.version}</version>
    </dependency>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>${org.mapstruct.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <!-- <version>1.7.25</version> -->
    </dependency>
    <!-- <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency> -->
    <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.0.3</version>
    <scope>test</scope>
</dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>2.0.0-beta</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.github.tomakehurst</groupId>
        <artifactId>wiremock</artifactId>
        <version>2.13.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <finalName>jirakpm</finalName>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>${maven-jaxb2-plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                <schemaIncludes>
                    <include>*.wsdl</include>
                </schemaIncludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.plugin.version}</version><!--$NO-MVN-MAN-VER$ -->
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${org.mapstruct.version}</version>
                    </path>
                </annotationProcessorPaths>
                <compilerArgs>
                    <compilerArg>
                        -Amapstruct.defaultComponentModel=spring
                    </compilerArg>
                </compilerArgs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>spring-boot</classifier>
                        <mainClass>
                            de.vwncova.defectadapter.JiraKpmAdapterControllerAndMain
                        </mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<repositories>
    <!-- <repository> <id>Attlassian-Maven-Legacy</id> <url>https://packages.atlassian.com/maven-closedsource-legacy/</url> 
        </repository> -->
    <repository>
        <id>Central Repository</id>
        <url>http://central.maven.org/maven2/</url>
    </repository>
    <repository>
        <id>Attlassian-Maven-External</id>
        <url>https://packages.atlassian.com/maven-hosted-atlas-external/</url>
    </repository>
    <repository>
        <id>Attlassian-Maven</id>
        <url>https://packages.atlassian.com/maven/</url>
    </repository>
    <repository>
        <id>atlassian-public</id>
        <url>https://packages.atlassian.com/maven/repository/public</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
        </snapshots>
        <releases>
            <enabled>true</enabled>
            <checksumPolicy>warn</checksumPolicy>
        </releases>
    </repository>
    <repository>
        <id>Attlassian</id>
        <url>https://maven.atlassian.com/content/repositories/atlassian-public/</url>
    </repository>
    <repository>
        <id>Attlassian-3d-Party</id>
        <url>https://maven.atlassian.com/3rdparty/</url>
    </repository>
</repositories>

2 个答案:

答案 0 :(得分:0)

事实是我试图访问ComponentAccessor而不是我运行SpringBoot应用程序的同一个VM。另一方面,我的SpringBoot应用程序试图通过REST访问JIRA服务器API(显然在不同的VM中运行)。 ComponentAccessor仅在我的代码在JIRA服务器端运行时才可访问,例如作为JIRA插件。 因此,在这种情况下我无法使用ComponentAccessor

答案 1 :(得分:0)

实际上,如果你真的想要访问jira函数,你应该将jira-api和jira-core以及其他依赖jar添加到你的pom文件中,用@WebListener LauncherContextListener重新启动你的springboot项目,当然,发生了很多错误根据日志,解决了它们,这将起作用。