JavaSpring:main方法称为duplicate
主方法称为复制。JavaSpring:main方法称为duplicate,java,spring-boot,Java,Spring Boot,主方法称为复制。 我怎样才能防止这种情况 @SpringBootApplication public class MyApplication{ public static void main(String[] args) { System.out.println("main "+args); SpringApplication.run(MyApplication.class, args); } } 使用以下命令运行 $ mv
我怎样才能防止这种情况
@SpringBootApplication
public class MyApplication{
public static void main(String[] args) {
System.out.println("main "+args);
SpringApplication.run(MyApplication.class, args);
}
}
使用以下命令运行
$ mvn spring-boot:run
输出
main [Ljava.lang.String;@1cf4f579
main [Ljava.lang.String;@1cf4f579 <------- I cannot understand THIS.
这是由spring boot开发工具引起的。如果类路径中存在依赖项,devtools将在类路径中的文件发生任何更改时自动注册并重新启动应用程序。这也可以在log语句中看到,因为所有日志都将从“restartedMain”线程记录,而不是像在没有devtools的Spring引导应用程序中那样从“main”线程记录 使用devtools登录:
2021-03-08 21:27:05.508 INFO 25824 --- [ restartedMain] com.example.demo.MyApplication : Starting MyApplication
2021-03-08 21:24:06.624 INFO 3652 --- [ main] com.example.demo.MyApplication : Starting MyApplication
不使用devtools的日志:
2021-03-08 21:27:05.508 INFO 25824 --- [ restartedMain] com.example.demo.MyApplication : Starting MyApplication
2021-03-08 21:24:06.624 INFO 3652 --- [ main] com.example.demo.MyApplication : Starting MyApplication
简而言之:这是预期的行为,不应该引起任何问题,因为(1)无论如何不应该在Spring Boot应用程序的主方法中运行任何附加代码,(2)不应该在应用程序的生产版本中打包Spring Boot devtools。这是由Spring Boot devtools引起的。如果类路径中存在依赖项,devtools将在类路径中的文件发生任何更改时自动注册并重新启动应用程序。这也可以在log语句中看到,因为所有日志都将从“restartedMain”线程记录,而不是像在没有devtools的Spring引导应用程序中那样从“main”线程记录 使用devtools登录:
2021-03-08 21:27:05.508 INFO 25824 --- [ restartedMain] com.example.demo.MyApplication : Starting MyApplication
2021-03-08 21:24:06.624 INFO 3652 --- [ main] com.example.demo.MyApplication : Starting MyApplication
不使用devtools的日志:
2021-03-08 21:27:05.508 INFO 25824 --- [ restartedMain] com.example.demo.MyApplication : Starting MyApplication
2021-03-08 21:24:06.624 INFO 3652 --- [ main] com.example.demo.MyApplication : Starting MyApplication
简而言之:这是预期的行为,不应该引起任何问题,因为(1)无论如何,您不应该在Spring Boot应用程序的主方法中运行任何附加代码,(2)您不应该在应用程序的生产版本中打包Spring Boot devtools。您如何运行您的程序?在命令行上,在IDE中…?我正在运行带有
mvn spring boot:run
的项目,您有哪些依赖项?具体来说,你的类路径上有spring boot开发工具吗?你如何运行你的程序?在命令行上,在IDE中…?我正在运行带有mvn spring boot:run
的项目,您有哪些依赖项?具体地说,您的类路径上有spring boot devtools吗?是的,我安装了devtools
,但是,这与nodemon
的功能不同,不确定您对nodemon的意思是什么,没有听说过与spring boot结合使用:nodemon是节点开发工具:在文件更改后重新启动项目是的,我安装了devtools
,但是,它的功能与nodemon
不确定nodemon是什么意思,还没有听说它与Spring Boot结合使用:nodemon是节点开发工具:用于在文件更改后重新启动项目