IntelliJ IDEA Sringboot 项目部署到外部Tomcat服务器

<packaging>war</packaging>

  添加依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

  

      排除自带tomcat,不排除也没有影响,只是多了个jar包

<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>

  

注释spring-boot-maven-plugin,使用maven-war-plugin

<!-- 
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>bing.AuthorityApplication</mainClass>
        <layout>ZIP</layout>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin> -->

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

  修改启动类

//@SpringBootApplication
//public class SpringlearnApplication {
//
//	public static void main(String[] args) {
//		SpringApplication.run(SpringlearnApplication.class, args);
//	}
//}

@SpringBootApplication
public class SpringlearnApplication extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(SpringlearnApplication.class);
	}

	public static void main(String[] args )
	{
		SpringApplication.run(SpringlearnApplication.class, args);
	}
}

 打包生成war

从根目录启动,其中xxx为war的名称

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
    
    
    <Context path="" docBase="xxx" debug="0" reloadable="true"/>
    
    ...
</Host>

  

posted @ 2018-10-18 17:51  南下玩技术  阅读(858)  评论(0编辑  收藏  举报