此内容没有您所选择的语言版本。
Appendix C. Deploying a Spring Boot application using WAR files
As an alternative to the supported application packaging and deployment workflow using fat JAR files, you can package and deploy a Spring Boot application as a WAR (Web Application Archive) file. You must configure your build and deployment settings to ensure that your application builds and deploys correctly on OpenShift.
Prerequisites
- A Spring Boot application.
- Fabric8 Maven Plugin used to deploy your application to OpenShift.
- Spring Boot Maven Plugin used to package your application.
Procedure
Add
warpackaging to thepom.xmlfile of your project:Example
pom.xml<project ...> ... <packaging>war</packaging> ... </project>
<project ...> ... <packaging>war</packaging> ... </project>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Specify
spring-boot-starter-tomcatas a dependency of your application:Example
pom.xmlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure the
repackageMaven goal for the Spring Boot Maven plugin is defined in thepom.xmlfile:Example
pom.xmlCopy to Clipboard Copied! Toggle word wrap Toggle overflow This ensures that the Spring Boot classes used to launch the application are included in the WAR file, and that the corresponding properties for these classes are defined in the
MANIFEST.mffile of the WAR file:-
Main-Class: org.springframework.boot.loader.WarLauncher -
Spring-Boot-Classes: WEB-INF/classes/ -
Spring-Boot-Lib: WEB-INF/lib/ -
Spring-Boot-Version: 2.4.9
-
Add the
ARTIFACT_COPY_ARGSenvironment variable to thepom.xmlfile.The Fabric8 Maven Plugin consumes this variable during the build process and ensures that the Build and Deploy tool uses the WAR file (rather than the default fat JAR file) to create the application container image:
Example
pom.xmlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the
JAVA_APP_JARenvironment variable to thesrc/main/fabric8/deployment.ymlfile.This variable instructs the Fabric8 Maven Plugin to launch your application using the WAR file included with the container. If
src/main/fabric8/deployment.ymldoes not exist, you can create it.Example
deployment.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Build and deploy your application:
mvn clean fabric8:deploy -Popenshift
mvn clean fabric8:deploy -PopenshiftCopy to Clipboard Copied! Toggle word wrap Toggle overflow