Spring-boot jersey maven未能运行war文件 [英] Spring-boot jersey maven failed to run war file

查看:405
本文介绍了Spring-boot jersey maven未能运行war文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在创建一个弹簧靴衫应用程序。
现在我们要创建可执行的war文件。
问题是当我运行它时应用程序正常运行

We are creating a spring-boot jersey application. Now we want to create executable war file. The problem is the application runs fine when I run it with

  mvn spring-boot:run 

但是当我尝试将其打包为war并使用java -jar ABD.war
运行时以下错误

But when I try to package it to war and run it with java -jar ABD.war its giving the following error

 Caused by: java.io.FileNotFoundException:       /Users/ABC/ABD-0.0.1-SNAPSHOT.war!/WEB-INF/classes (No such file or directory)


 Caused by: org.glassfish.jersey.server.internal.scanning.ResourceFinderException:

以下是我正在使用的pom.xml的一部分,

Here are the part of pom.xml I'm using ,

<packaging>war</packaging>
.
.
.

 <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>


        <org.slf4j.version>1.7.7</org.slf4j.version>

        <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>

        <java.version>1.8</java.version>


  </properties>

.
.
.
.
.
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

虽然当我解压war文件时,我可以看到WEB-INF / classes文件夹。

Although when I unpack the war file I can see the WEB-INF/classes folder is there.

推荐答案

确定找到了解决方案。
我有一个jersery配置类,我在其中添加了所有带有packages()的控制器类。
当我评论它并将其更改为注册(controller.class)它开始工作!

OK found the solution. I have a jersery config class, where I added all of controllers class with packages(). When I commented it out and change it to register("controller.class") It started to work!

    @Configuration
    @ApplicationPath("/path")
    @Controller 
    public class JerseyConfig extends ResourceConfig {
        public JerseyConfig() {
            register(MultiPartFeature.class);
           register(OneController.class);
          //packages("com.controllers");
        }
    }





更新

#

Update

private static final Logger logger = LoggerFactory.getLogger(OneController.class);

  public JerseyConfig() {
     scan("com.somepackages");
  }

  public void scan(String... packages) {
      for (String pack : packages) {
          Reflections reflections = new Reflections(pack);
           reflections.getTypesAnnotatedWith(Path.class)
           .parallelStream()
           .forEach((clazz) -> {
              logger.info("New resource registered: " + clazz.getName());
           register(clazz);
      });
 }

}

使用此解决方案,您可以通过包裹扫描获得球衣注册中的所有控制器。

With this solution you can get all controllers in jersey register through package scan.

这篇关于Spring-boot jersey maven未能运行war文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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