Spring-boot jersey maven failed to start war file

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

  mvn spring-boot:run 

      

But when I try to pack it into war and run it with java -jar ABD.war it gives 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:

      

Here is the pom.xml part I am 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>

      

Although when unpacking the war file, I see the WEB-INF / classes folder.

+3


source to share


1 answer


OK found a solution. I have a jersery config class where I added the whole controller class with packages (). When I commented this out and changed it to register ("controller.class") it started working!

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

      

#

Refresh



#
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 via packet scan.

+7


source







All Articles