✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.
Was wird ausgegeben, wenn man die Anwendung startet: [EK]
@Scope("singleton")
@Component
public class GreeterSingleton{
private static int lastId = 0
;
private final int id = ++lastId
;
@Override
public String toString() {
return "GreeterSingleton " + id
;
}
}
@Component
public class ProfileTester implements CommandLineRunner{
@Autowired
private GreeterSingleton greeterSingleton
;
@Autowired
private ApplicationContext context;
@Override
public void run(String... args) throws Exception{
System.out.println(greeterSingleton + "\n" + context.getBean(GreeterSingleton.class
));
}
}