Why did you make Springboot a war bag?
Under normal circumstances, the Springboot item is in the form of a jar package, via the command line:
java -jar demo.jar
To run, and Springboot is an embedded tomcat server, so every reboot is a new tomcat server. For this reason, there is also a problem:
Files uploaded to the project, if saved in the project, will be lost after the reboot. For example, when we uploaded an Avatar and restarted the project, the Avatar was gone. If you save the file on a local disk, there is no way to get the tags in the HTML. Therefore, we need to make the Springboot project into a war package and put it into Tomcat to run.
Modify method
Add the following dependencies in the Pom.xml file:
<!--因配置外部TOMCAT 而配置--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
Also, change the jar of the Pom.xml file header to war
<groupId>com.star</groupId> <artifactId>yiyong</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <!--<packaging>jar</packaging>-->
Finally, start the class from the
@SpringBootApplicationpublic class YiyongApplication { public static void main(String[] args) { SpringApplication.run(YiyongApplication.class, args); }}
Revision changed to
@SpringBootAppli Cationpublic class yiyongapplication extends springbootservletinitializer{ @Override protected Springapplicationbuilder configure (Springapplicationbuilder builder) {return builder.sources (Yiyongapplication.class); } public static void main (string[] args) {Springapplication.run (yiyongapplication.class, args);}}
Note: This class inherits the Springbootservletinitializer and overrides the Configure method, which is the key.
Packaged deployment
On the right of idea maven bar double-click the package to wait for build success.
Then put the war package in the target directory under Tomcat's WebApps directory and launch Tomcat to automatically unzip the deployment.
Finally, enter in the browser
http://localhost:[端口号]/[打包项目名]/
Publishing success
How to make a springboot easily into a war package (go)