我有一个非常简单的 spring 应用程序,但配置错误:
@SpringBootApplication()
public class SimpleApplication implements CommandLineRunner {
public static void main(String[] args) {
var ctx = SpringApplication.run(SimpleApplication.class, args);
System.exit(SpringApplication.exit(ctx));
}
public static class MyObject {}
//Oops - No bean provided!!!
@Autowired MyObject myObject;
@Override public void run(String... args) { }
}
我收到以下错误(在 intellij 中):
...
Consider defining a bean of type 'test.app.SimpleApplication$MyObject' in your configuration.
Process finished with exit code 1
这正是我所期望的。
如果我spring-boot-devtools
在maven中添加依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
然后我得到以下信息:
...
Consider defining a bean of type 'test.app.SimpleApplication$MyObject' in your configuration.
Process finished with exit code 0
看来添加这个包会导致spring boot返回错误的代码。