【发布时间】:2018-11-08 18:00:35
【问题描述】:
我正在尝试打包使用 Jersey 的 Spring Boot 应用程序。在开发过程中启动应用程序时运行没有问题,当我使用
生成 jar 文件时出现问题mvnw package && java -jar target/gs-spring-boot-docker-0.1.0.jar
这会产生以下错误。
使用名称“org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration”创建 bean 时出错:不满足依赖 ency 通过构造函数参数 1 表示;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“jerseyConfig”的 bean 时出错 在 URL [jar:file:..path/Backend/target/celulascontentas-2.0.jar!/BOOT-INF/classes!/tech/aabo/celulascontenta 中定义 s/config/JerseyConfig.class]:bean 的实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [tech.aabo.ce lulascontentas.config.JerseyConfig]:构造函数抛出异常;嵌套异常是 org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.File NotFoundException: ..path\Backend\target\celulascontentas-2.0.jar!\BOOT-INF\classes (系统找不到路径 指定)
我的 Jersey 配置如下所示:
package tech.aabo.celulascontentas.config;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
import org.springframework.stereotype.Component;
import javax.ws.rs.ApplicationPath;
@Component
@ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(JacksonJaxbJsonProvider.class);
packages("tech.aabo.celulascontentas.endpoint");
property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
}
}
我的 pom.xml 看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<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>tech.aabo</groupId>
<artifactId>celulascontentas</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
<name>celulascontentas</name>
<description>API para celulas contentas</description>
<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>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- Core -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- DB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Extra -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.133</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我尝试了各种组合,但总是产生相同的错误。那些人现在如何解决它?
谢谢
【问题讨论】:
标签: java spring maven spring-boot jersey