[英]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.