In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
I believe many inexperienced people are at a loss about the two ways to deploy a springboot project to a CVM. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Springboot version: 2.0.3.RELEASE
CVM: Ali Cloud ECS CentOS 7.364-bit
IDE:IntelliJ IDEA
Server remote connection tool: Xshell 5
Way 1. Add maven dependencies by running as jar file
Spring Boot runs as a jar package by default
You can configure the following plug-ins in Maven to export Spring Boot to an executable jar file.
Org.springframework.boot spring-boot-maven-plugin packages the project
Run mvn package from the run command line under the project directory:
> mvn package
* it is recommended to use the graphical interface in IDE
(the operation in the figure is to skip test packaging)
Package will package the Maven project into an executable jar file and store it in the target directory. If you see the following output in the console, the output is successful:
Put the jar file on the server
The packaged jar files have been stored in the target directory
Put the jar file in the appropriate directory on the server
(this article uses direct mouse drag and drop, and you can also use rz commands, FileZilla tools, etc.)
Run the jar file on the server
Change to the directory where the jar file is located and execute the command (provided that jdk is installed on the server)
Java-jar yourProjectName.jar
Browser access
Enter an address in the browser to access
Note that compared with running on the local computer, you only need to change the ip address to the server. The port number and path name are the same as when running on the local computer, that is, the same as the yml configuration file.
At this point, the project deployment is complete.
2. Deploy in war mode
Spring Boot comes with an embedded Tomcat server by default, which can be run in jar mode. More commonly, Spring Boot applications need to be packed into a war package and deployed to servers such as Tomcat.
Modify the packing method
In this case, you need to change the packaging in pom to war:
Remove embedded tomcat plug-in
There are 2 ways to use this project (mode 2)
Method 1. You need to change the embedded Tomcat dependency mode to provided (add the dependent package to the classpath of the project when compiling and testing, and do not add it at runtime, which can be understood as not using the Tomcat that comes with Spring Boot at runtime)
Org.springframework.boot spring-boot-starter-tomcat provided
Mode 2. Find the spring-boot-starter-web dependency node in pom.xml and add the following code to it
Org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat
Add dependencies for servlet-api
Javax.servlet javax.servlet-api 3.1.0 provided
Modify the startup class and override the initialization method
Packing
The operation procedure is the same as that of jar packaging. After the packaging is completed, a .war file will be generated in the target directory.
Deployment
Put the war file in the webapps directory of Tomcat and start Tomcat (execute. / startup.sh under the bin directory) to automatically extract the deployment.
Browser access
The access address is:
Http:// server ip: the port / project name / interface path configured by Tomcat in the server
* Note: the project name is subject to the name of the extracted folder under the webapps directory of Tomcat.
The server configuration under the yml file does not work because the Tomcat that comes with Spring Boot is not used.
At this point, the project deployment is complete.
Summary:
1. Jar package deployment uses Tomcat that comes with Spring Boot. Because Spring Boot applications come with Tomcat, you can run jar files directly on the server.
2. War package deployment uses the Tomcat in the CVM. In this case, you need to remove the Tomcat plug-in that comes with Spring Boot.
3. Pay attention to the differences in access paths between the two deployment methods.
4. Note whether the port number used is open in the security group.
After reading the above, have you mastered the two ways to deploy a springboot project to a CVM? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.