Running a "fat" spring-boot war as an application

Hi,

there is something strange with running "fat" Spring Boot applications (i.e. these can be run as stand-alone applications or in a web container) e.g. https://github.com/spring-guides/gs-convert-jar-to-war-maven.git. Just import the project and run main in class Application. It seems to close the application context immediately and exits.

If one removes dependency

 
dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
 
then the application does run. It would be great if Intellij would support both modes. Any ideas what is wrong with this setup?
2 comments
Comment actions Permalink

This is a spring boot issue and nothing wrong with intellij.
The project you are referencing is not made for running as standalone jar. You need to build it as war file and deploy to a servlet container like tomcat.
As you say you need to remove the provided scope from spring-boot-starter-tomcat.
You can add an maven profile, which exclude this dependency, if you build the war file like this:

        <profiles>           <profile>                <id>PROD</id>                <dependencies>                     <dependency>                          <groupId>org.springframework.boot</groupId>                          <artifactId>spring-boot-starter-tomcat</artifactId>                          <scope>provided</scope>                     </dependency>                </dependencies>           </profile>      </profiles>

0
Comment actions Permalink

Well it is meant to be run as a standalone jar, that is the point of it being "fat".

java -jar ... does work even with the provided dependency but that only works because the main class is set to org.springframework.boot.loader.WarLauncher. I guess there is too much magic behind the scenes and your suggestion might be the wiser choice. Thanks.

0

Please sign in to leave a comment.