简体   繁体   中英

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. 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. 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() :

ConfigurableApplicationContext appContext = SpringApplication.run(...);
MyServiceClass myServiceClass = appContext.getBean(MyServiceClass.class);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM