无法从春季启动球衣运行生成的jar

种质

我无法在带有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-dependencies。

种质

这比使用包的实际有效解决方案(true,“ my.package”)更是一种解决方法。

关于Anton的答案,我对此解决方案进行了解决,其局限性是它需要使用类级别@Path或@Provider批注的资源:

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());
            }
        });

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章