1 springboot
project related
1.1 Modify pom.xml
file dependencies
If you want to change the final packaging form war
, you also need to pom.xml
modify the file, because spring-boot-starter-web
it contains embedded tomcat
containers, so direct deployment in external containers will result in conflicts and errors. There are two ways to solve it, as follows
method one:
web
Dependencies removed in tomcat
dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
Here you need to remove Tomcat
the dependency on embedded, so that the package will not contain related packages war
in the directory , otherwise a startup error will occur. There is also a very critical key point, that is , it must be .lib
Tomcat
jar
tomcat-embed-jasper
scope
provided
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
Method Two:
Because it SpringBootServletInitializer
needs to be dependent javax.servlet
, and there is this in the tomcat-embed-jasper
following , if it is useless , there will be this in the final build, which will conflict with itself. This key point also applies to the second method described below.tomcat-embed-core
javax.servlet
provided
war
servlet-api
jar
tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
provided
The role of the above has been introduced very thoroughly, so I won't repeat it here. The advantage of this method is that the packaged war
package is suitable for java -jar
command startup and deployment to external containers at the same time.
1.2 Modify the packaging method
<packaging>war</packaging>
1.3 Modify the startup class
If the external container is deployed, it cannot rely on Application
the main
function, but starts the Spring application context in a manner similar to the configuration of the web.xml file. At this time, we need to inherit SpringBootServletInitializer
and implement the configure
method in the startup class:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class Chapter05Application extends SpringBootServletInitializer {
[@Override](https://my.oschina.net/u/1162528)
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Chapter05Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Chapter05Application.class, args);
}
}
#2 tomcat
Related
2.1 Download
URL: http://tomcat.apache.org/
2.2 Unzip installation
Move the installation package to the location you want, then unzip it:
tar -zxvf apache-tomcat-8.5.34.tar.gz ./
Rename it so that later operations can save a little typing.
mv apache-tomcat-8.5.34 tomcat
Set environment variables
vim /etc/profile
At the end of the file add:
#set tomcat environment
CATALINA_HOME=/usr/local/tomcat
export CATALINA_HOME
Reload the configuration file for environment variables:
source /etc/profile
enter the tomcat
folder
cd /usr/local/tomcat
Edit catalina.sh
file:
vim bin/catalina.sh
Add to the front of the document:
CATALINA_HOME=/usr/local/tomcat
JAVA_HOME=/usr/local/java/jdk1.8.0_181
CATALINA_HOME
Yes tomcat
, the installation path is the installation path of JAVA_HOME
the JDK above. You can change the above path to your own installation path.
2.3 Starttomcat
current location is/usr/local/tomcat
./bin/startup.sh
The following information is displayed, indicating that the startup is successful:
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_181
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
2.4 Stop tomcat
./bin/shutdown.sh
2.5 Check tomcat
whether the installation is successful
Browser access to http://localhost:8080 will display tomcat information.
2.6 Modify the tomcat
port
vim /usr/local/tomcat/conf/server.xml
Find the location of port 8080 and modify it to 80.
2.7 tomcat
Set to start at boot
Copy catalina.sh
to the /etc/init.d
directory and rename totomcat
cp /usr/local/tomcat/bin/catalina.sh /etc/init.d/tomcat
Setting permissions
chmod +x /etc/init.d/tomcat
tomcat
For soft (or hard) connections created under the self-starting folder , K means no self-starting, and S means self-starting.
ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
Done, restart the test.
3 Deploy the project
All files tomcat
under deletedwebapps
rm -rf /usr/local/tomcat/webapps/*
tomcat
Upload the project 's war package to webapps
and rename it toROOT.war
Start tomcat and visit http://localhost .
Restart to test whether tomcat starts normally.