无法从Spring Boot球衣运行生成的jar [英] Unable to run generated jar from spring-boot jersey

查看:72
本文介绍了无法从Spring Boot球衣运行生成的jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在带有jersey项目的spring-boot中运行生成的jar文件.

Im unable to run the generated jar file with my spring-boot with jersey project.

例外是:

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

Project runs properly when it's done via IDE (running the Main class) or when using spring-boot:run

以下是当前设置的详细信息:

Here are the details of the current setup:

包装:

jar

依赖性:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-jersey</artifactId>
  <version>1.5.1.RELEASE</version>
</dependency>

我的球衣配置(ResourceConfig)设置为扫描包

my jersey configuration (ResourceConfig) is set to scan packages

@Component
public class JerseyConfiguration extends ResourceConfig {

    public JerseyConfiguration() {
        packages(true, "com.my.base.jaxrs.packages");
    }

}

spring-boot-maven-plugin配置为: org.springframework.boot

spring-boot-maven-plugin configured as: 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-dependencies.

I also did not use the spring-boot-starter-parent but added the spring-boot-dependencies as indicated in the docs.

推荐答案

与实际使用的有效解决方案相比,这更是一种解决方法 包装(true,"my.package");

This is more of a workaround than an actual valid solution to use packages(true, "my.package");

关于Anton的答案,我以这种解决方案解决了它的局限性,即它需要具有类级别@Path或@Provider批注的资源:

in reference to Anton's answer, i settled with this solution with the limitation that it requires resources with class level @Path or @Provider annotation:

ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
        provider.addIncludeFilter(new AnnotationTypeFilter(Path.class));
        provider.addIncludeFilter(new AnnotationTypeFilter(Provider.class));
        provider.findCandidateComponents("my.package.here").forEach(beanDefinition -> {
            try {
                LOGGER.info("registering {} to jersey config", beanDefinition.getBeanClassName());
                register(Class.forName(beanDefinition.getBeanClassName()));
            } catch (ClassNotFoundException e) {
                LOGGER.warn("Failed to register: {}", beanDefinition.getBeanClassName());
            }
        });

这篇关于无法从Spring Boot球衣运行生成的jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆