【问题标题】:eclipse shutdown button can not shutdown embedded tomcat used fo spring booteclipse关闭按钮无法关闭用于spring boot的嵌入式tomcat
【发布时间】:2016-09-13 12:02:58
【问题描述】:

我在我的 Spring Boot 应用程序中使用嵌入式 tomcat。 我调整应用程序的目标如下:

clean spring-boot:run

它运行没有错误。我使用eclipse关闭按钮将其关闭。 我第二次尝试运行它,我得到了这个:

Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project cpanel: Failed to clean project: Failed to delete XXXXXXXXX\target\classes\hibernate\security\user\User.hbm.xml -> [Help 1]

it sims tomcat 下次无法删除目标。我的tomcat怎么了? 我是不是做错了什么?

application.yml 中我的服务器配置:

server:
compression:
    enabled: true
port: 8080
servlet-path: /rest

还有我的 tomcat 依赖:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

【问题讨论】:

  • 我怀疑spring-boot:run 已经分叉了第二个JVM,而Eclipse 并没有正确关闭它们。我会通过直接在 Eclipse 中运行你的主类而不是通过 Eclipse 的 Maven 集成来运行它,从而将 Maven 完全排除在外。

标签: spring-boot embedded-tomcat-8


【解决方案1】:

只需在 pom.xml 文件中的 spring-boot-maven-plugin 中添加如下 Tag

            <configuration>
                <fork>false</fork>
            </configuration>

这里是完整的例子:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <fork>false</fork>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

【讨论】:

    【解决方案2】:

    我写了这个bat脚本命令:

    FOR /F "tokens=5 delims= " %%P IN ('netstat -a -n -o ^| findstr :8080.*LISTENING') DO TaskKill.exe /PID %%P /F pause 并将其保存在killport.bat 中,然后使用 maven-antrun-plugin 调用它:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <executions>
            <execution>
                <phase>compile</phase>
                <configuration>
                    <target>
                        <exec executable="cmd.exe" spawn="true">
                            <arg value="/c" />
                            <arg value="F:\Java\Projects\killport.bat" />
                        </exec>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

      【解决方案3】:

      要解决这个问题,把tomcat maven plugin改成forkfalse

         <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
              <configuration>
                  <fork>false</fork>
              </configuration>
        </plugin>
      

      【讨论】:

      • 虽然这通过不分叉有效,但我遇到了其他依赖冲突。我只是右键单击我的主类和Run As &gt; Java App。当你停止时,tomcat 就会停止。
      猜你喜欢
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      • 2016-08-19
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 2020-07-24
      相关资源
      最近更新 更多