Now I look for my first job and I received a test task from one company. So, I did and sent it for review. I was refused because of a bad design code. Here is my code with the main method:
package com.lapinskyi.universitytest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import com.lapinskyi.universitytest.console_menu.Menu;
@SpringBootApplication
public class Main {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Main.class, args);
Menu menu = context.getBean(Menu.class);
System.out.println("Hello!");
boolean isContinue = true;
while(isContinue) {
menu.getMenu();
menu.makeChoosenAction();
isContinue = menu.isContinue();
}
System.out.println("Good bye");
}
}
This code was commented like this:
It's not a good idea to work with ApplicationContext directly to get beans, you should use the Dependency injection mechanism of the Spring Framework for that (Menu class).
So, help me, please, how can I get a bean of the class Menu in static method main not using context directly?