[英]Initializing Service and Repository Classes in Springboot Application Class
I want to create a Springboot application where I am taking input from stdin, storing it into H2 db and showing results on stdout. 我想创建一个Springboot应用程序,我将从stdin接收输入,将其存储到H2 db中,并在stdout上显示结果。 Right now I am trying to do it in main application class after SpringApplication.run(), but it's not able to Autowire my Service and Repository classes.
现在,我正在尝试在SpringApplication.run()之后的主应用程序类中执行此操作,但是它无法自动装配Service和Repository类。 What is a better way of doing this?
有什么更好的方法?
Thanks 谢谢
You can access your beans by getting them from the application context after calling SpringApplication.run() : 您可以通过在调用SpringApplication.run()之后从应用程序上下文中获取bean来访问它们:
ConfigurableApplicationContext appContext = SpringApplication.run(...);
MyServiceClass myServiceClass = appContext.getBean(MyServiceClass.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.