简体   繁体   English

从intelliJ执行文件IO时Spring Boot自动重启

[英]Spring boot automatically restarts when doing file IO from intelliJ

I have a very strange issue where my spring application will end all threads and restart when I programmatically save a file to the resources folder. 我有一个非常奇怪的问题,当我以编程方式将文件保存到资源文件夹时,spring应用程序将结束所有线程并重新启动。 What's odd is that the problem seems to disappear if I package to war and deploy on a tomcat server, yet when I run it from IntelliJ the problem is there. 奇怪的是,如果我打包打包并在tomcat服务器上部署,问题似乎消失了,但是当我从IntelliJ运行它时,问题就在那里了。 What's more is that I am wanting this file write to happen right after Spring starts, leading to this infinite loop of the application starting and restarting. 更重要的是,我希望在Spring启动后立即进行此文件写入,从而导致应用程序启动和重启的无限循环。 I check in the resources folder within the build folder and see that the file is getting save each time spring starts, but the application seems to crash right afterwards. 我检查了build文件夹中的resources文件夹,发现每次spring启动时该文件都得到保存,但是此后该应用程序似乎崩溃了。

Here is the code I'm using to write the file: 这是我用来写文件的代码:

FileOutputStream fos = new FileOutputStream(
        this.getClass().getClassLoader().getResource("processes/").getPath() + "/filename.xml"
);
fos.write(processXML);
fos.close();

That is not strange at all. 那一点也不奇怪。

You are having in your classpath dependency: 您在类路径依赖项中:

org.springframework.boot:spring-boot-devtools

You are writing to the location that is being scanned for changes by spring boot reload component - which results in infinite loop as you said. 您正在写入Spring Boot重新加载组件正在扫描的位置更改-如您所说,这将导致无限循环。

Set in your application.properties: 在您的application.properties中设置:

spring.devtools.restart.enabled = false

More on that here: 这里的更多信息:

https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html https://docs.spring.io/spring-boot/docs/current/reference/html/howto-hotswapping.html https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html https://docs.spring.io/spring-boot/docs/current/reference/html /howto-hotswapping.html

Just add two things first devtools dependency in pom.xml and property in yml file. 只需在pom.xml中添加两个首先为devtools的依赖关系,并在yml文件中添加属性。

#for not restarting the server every time
spring.devtools.restart.enabled:  false

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Intellij 上使用 Maven 执行 Spring Boot 应用程序时,JavaScript 会进入哪个文件夹? - Which folder does JavaScript go into when doing a Spring Boot application with Maven on Intellij? 从Eclipse到IntelliJ的Spring Boot - Spring Boot from Eclipse to IntelliJ 使用 IntelliJ 从 PropertiesLoader 加载的 Spring Boot 模块时出现 NoClassDefFoundError - NoClassDefFoundError when using Spring Boot modules loaded from PropertiesLoader by IntelliJ 尝试从intelliJ运行/调试Spring Boot示例时发生异常 - Exception when trying to run/debug spring boot example from intelliJ 从 IntelliJ 启动时无法激活 Spring 引导配置文件 - It is not possible to activate the Spring boot profile when starting from IntelliJ Spring-boot应用程序重启时HSQL数据库丢失 - HSQL DB lost when spring-boot app restarts spring boot 应用程序适用于 intellij 但不适用于 .jar 文件 - spring boot app works on intellij but not with .jar file 执行 findAll() 时 Spring boot 和 couchbase 中的 InvalidDataAccessResourceUsageException - InvalidDataAccessResourceUsageException in Spring boot and couchbase when doing findAll() IntelliJ Spring Boot Run无法自动加载application.yml - intellij spring boot run cannot load application.yml automatically 使用 spring 引导从 eclipse 移动到 intellij - moving from eclipse to intellij with spring boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM