El proyecto springboot se empaqueta en guerra y se implementa en Tomcat
Embalar
pom.xml
Modificar embalaje
Cambiar tarro a guerra
<!-- <packaging>jar</packaging>-->
<packaging>war</packaging>
agregar dependencias
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope>-->
<!-- 如果不注释,你会发现main线程运行报404错误,必须使用 spring-boot:run这个命令运行才行。所以我们注释掉-->
</dependency>
<!--添加servlet-api的依赖,用来打war包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
modificar dependencias
1. Voluntad
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
cambiado a
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<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>
2. Voluntad
<finalName>phoneshow</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
cambiado a
<finalName>phoneshow</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--配置springboot入口类-->
<configuration>
<fork>true</fork>
<jvmArguments>Dfile.encoding=UTF-8</jvmArguments>
<!--配置入口类的标签名-->
<mainClass>com.phoneback</mainClass>
</configuration>
</plugin>
</plugins>
</build>
clase de inicio
Voluntad
public class DemocopyApplication{
public static void main(String[] args) {
SpringApplication.run(DemocopyApplication.class, args);
}
}
cambie a
public class DemocopyApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(DemocopyApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
return builder.sources(DemocopyApplication.class);
}
}
desplegar
implementar un proyecto
Colóquelo en la carpeta de aplicaciones web de tomcat. Haga
doble clic en startup.bat en el contenedor para ejecutar
el método de acceso:
http://localhost:8080/nombre del proyecto.
Implementar múltiples proyectos en diferentes puertos
Modifique el archivo server.xml en la carpeta conf.
Después de eliminar el contenido del comentario original, se mostrará:
Haga una copia, cambie el nombre del servicio y el motor a otro (debe ser el mismo), modifique el nuevo nombre de la base de aplicaciones del host y cambie el puerto al número de puerto que desee.
Si desea acceder sin agregar el siguiente nombre de proyecto, como se muestra arriba:
<Context path="" docBase="phoneshow" reloadable="true" />
docBase es el nombre del proyecto.