简体   繁体   English

Spring-boot jersey maven未能运行war文件

[英]Spring-boot jersey maven failed to run war file

We are creating a spring-boot jersey application. 我们正在创建一个弹簧靴衫应用程序。 Now we want to create executable war file. 现在我们要创建可执行的war文件。 The problem is the application runs fine when I run it with 问题是当我运行它时,应用程序运行正常

  mvn spring-boot:run 

But when I try to package it to war and run it with java -jar ABD.war its giving the following error 但是当我尝试将其打包为war并使用java -jar ABD.war运行它时会出现以下错误

 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:

Here are the part of pom.xml I'm using , 这是我正在使用的pom.xml的一部分,

<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>

Although when I unpack the war file I can see the WEB-INF/classes folder is there. 虽然当我解压war文件时,我可以看到WEB-INF / classes文件夹。

OK found the solution. 好的找到了解决方案。 I have a jersery config class, where I added all of controllers class with packages(). 我有一个jersery配置类,我在其中添加了所有带有packages()的控制器类。 When I commented it out and change it to register("controller.class") It started to work! 当我评论它并将其更改为注册(“controller.class”)它开始工作!

    @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. 使用此解决方案,您可以通过包扫描获得球衣寄存器中的所有控制器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何正确编写 Docker 文件来构建 war 文件并运行 spring-boot maven 项目? - How write correctly a Docker file to build war file and run spring-boot maven project? 使用maven为spring-boot Web应用程序生成一个工作war文件 - generating a working war file with maven for a spring-boot web application 带有JSP项目的Spring-Boot无法与jar或war文件一起运行 - Spring-Boot with JSP project not able to run with jar or war file Maven上带有war文件的spring-boot jackson错误,但带有com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z的jar文件不存在 - Spring-boot jackson error on Maven with war file, but not jar file with com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z 在专用的tomcat上将spring-boot应用程序部署为war文件是行不通的 - Deploying a spring-boot application as a war file on a dedicated tomcat is not working Spring-Boot无法在WAR文件中查找JSP页面 - Spring-Boot Not Finding JSP Pages in WAR File 使用 jar 文件运行时出现 Whitelabel 错误,但使用 war 文件以及使用命令 mvn spring-boot:run 运行时工作正常 - Whitelabel error when running with jar file, but works fine with war file and when run with command mvn spring-boot:run 如何运行gulp任务和spring-boot:与maven一起运行? - How to run gulp task and spring-boot:run together with maven? intellij 想法,maven spring-boot:运行不:不停止 - intellij idea, maven spring-boot:run doesn:'t stop spring-boot,maven:无法运行或打包应用程序 - spring-boot, maven: failing to run or package an application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM