springbootfeignstarter

1.spring boot war包部署到Tomcat和devt

2017-04-11  本文已影响813人  会灰的大飞狼

1.pom.xml

(因为spring-boot-starter-thymeleaf包含了spring-boot-starter-web,所以不用引入了)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!-- ... -->
    <packaging>war</packaging>
    <!-- ... -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!-- 排除自带的tomcat,用自己的tomcat -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- 热部署 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2.增加一个类,如果新建项目的时候选的war,这步可以略过:

package com.yunchuang;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Demo8Application.class);
    }
}

3.application.yml 定义端口号和path

server:
#  端口号
  port: 8008
  context-path: /demo8

4.thymeleaf缓存设置为false

spring:
  thymeleaf:
    cache: false

以上是代码部分,配置完毕.下面是idea配置部分.

点击工具栏上的EditConfigurations

Paste_Image.png

点击左侧的+号,找到Tomcat Server,点击local

Paste_Image.png

配置tomcat,先改名,然后点击Deployment,点击+号,增加这么一项.

Paste_Image.png

点击server标签:

Paste_Image.png

然后debug运行tomcat后,点击图上的update.

Paste_Image.png

勾选Update classes and resources和Don't ask again

Paste_Image.png

选择打包位置和名字

Paste_Image.png Paste_Image.png

部署按钮

Paste_Image.png Paste_Image.png

热部署配置:

Paste_Image.png

ctrl+shift+alt+/

Paste_Image.png Paste_Image.png
上一篇下一篇

猜你喜欢

热点阅读