具体修改的步骤如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--以下是在tomcat运行比spring boot多引的包-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
以上两个依赖还需要引入下边一个spring boot的父依赖。
<!-- Spring Boot 启动父依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
为了访问到jsp页面还需要加jstl依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
为了部署到tomcat里,那packing
标签必须要改成war
<packaging>war</packaging>
package microservice.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
/**
* 即继承SpringBootServletInitializer类,并重写它的 configure方法即可
*/
@SpringBootApplication
public class CreateModelApplication extends SpringBootServletInitializer{
public static void main(String[] args){
SpringApplication.run(CreateModelApplication.class,args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(CreateModelApplication.class);
}
}
注意了,这样配置,并不是说只能用tomcat来启动,也是可以直接main方法启动的,瞬间高大上了不是?
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>application.properties</include>
<include>dubbo-consumer.xml</include>
<include>logback-spring.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<!--这里是将webapp下的文件都打包复制到下边目录下 -->
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<!--下边的这个resource,这个其实在这里没有用,可以删掉--> <directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/qq_43842093/article/details/121568903
内容来源于网络,如有侵权,请联系作者删除!