天天看點

Intellij IDEA 使用Spring-boot-devTools無效解決辦法配置devtools1.maven配置

配置devtools

1.maven配置

在pom.xml檔案中,增加如下插件依賴

<!--devtools可以實作頁面熱部署(即頁面修改後會立即生效,這個可以直接在application.properties檔案中配置spring.thymeleaf.cache=false來實作),
                   實作類檔案熱部署(類檔案修改後不會立即生效),實作對屬性檔案的熱部署。
                   即devtools會監聽classpath下的檔案變動,并且會立即重新開機應用(發生在儲存時機),注意:因為其采用的虛拟機機制,該項重新開機是很快的
                -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional><!-- optional=true,依賴不會傳遞,該項目依賴devtools;之後依賴myboot項目的項目如果想要使用devtools,需要重新引入 -->
        </dependency>
           

在pom.xml檔案中,增加如下插件

<build>
        <plugins>
            <!-- 用于将應用打成可直接運作的jar(該jar就是用于生産環境中的jar) 值得注意的是,如果沒有引用spring-boot-starter-parent做parent,
               且采用了上述的第二種方式,這裡也要做出相應的改動 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork><!-- 如果沒有該項配置,肯呢個devtools不會起作用,即應用不會restart -->
                </configuration>
            </plugin>
            <!-- spring Boot在編譯的時候,是有預設JDK版本的,如果我們期望使用我們要的JDK版本的話,那麼要配置呢 -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
           

Eclipse

如果是eclipse開發,現在已經可以重新開機項目來使用了。但是idea的話,請看第二步的設定!
           

Intellij IDEA配置

1.設定中打開settings

Intellij IDEA 使用Spring-boot-devTools無效解決辦法配置devtools1.maven配置

2.按快捷鍵 Shift+Ctrl+Alt+/ ,選擇 Registry

Intellij IDEA 使用Spring-boot-devTools無效解決辦法配置devtools1.maven配置

3.勾選compiler.automake.allow.when.app.running

Intellij IDEA 使用Spring-boot-devTools無效解決辦法配置devtools1.maven配置

繼續閱讀