我正在构建一个将从命令行调用的Spring Boot应用程序.
我将传递给应用程序一些参数,但我在从这个类调用服务时遇到问题:
@SpringBootApplication
public class App{
public static void main(String[] args) {
SpringApplication.run(App.class,args);
App app = new App();
app.myMethod();
}
@Autowired
private MyService myService;
private void myMethod(){
myService.save();
}
}
Exception in thread "main" java.lang.NullPointerException
at com.ef.Parser.App.myMethod(Application.java:26)
at com.ef.Parser.App.main(Application.java:18)
最佳答案