我无法使用带有 jersey 项目的 spring-boot 运行生成的 jar 文件。
我遇到的例外是:
Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 1
通过 IDE(运行 Main 类)或使用 spring-boot:run 完成项目时,项目可以正常运行
以下是当前设置的详细信息:
包装:
jar
依赖性:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
我的球衣配置(ResourceConfig)设置为扫描包
@Component
public class JerseyConfiguration extends ResourceConfig {
public JerseyConfiguration() {
packages(true, "com.my.base.jaxrs.packages");
}
}
spring-boot-maven-plugin 配置为:
org.springframework.boot
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
我也没有使用 spring-boot-starter-parent 但添加了 spring-boot-dependency,如文档中所示。