From de87a6ad316f28ebebcc2f4b35e1ad363998ebb5 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Tue, 19 Jan 2021 12:32:52 +0000 Subject: [PATCH] Explicitly Define Prototype Bean Scope --- Spring/src/main/java/conference/AppConfig.java | 2 +- Spring/src/main/java/conference/Application.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Spring/src/main/java/conference/AppConfig.java b/Spring/src/main/java/conference/AppConfig.java index ce759a8..74e6917 100644 --- a/Spring/src/main/java/conference/AppConfig.java +++ b/Spring/src/main/java/conference/AppConfig.java @@ -14,7 +14,7 @@ import org.springframework.context.annotation.Scope; public class AppConfig { @Bean(name = "speakerService") - @Scope(value = BeanDefinition.SCOPE_SINGLETON) + @Scope(value = BeanDefinition.SCOPE_PROTOTYPE) public SpeakerService getSpeakerService() { return new SpeakerServiceImpl(getSpeakerRepository()); } diff --git a/Spring/src/main/java/conference/Application.java b/Spring/src/main/java/conference/Application.java index b402a53..b35eb89 100644 --- a/Spring/src/main/java/conference/Application.java +++ b/Spring/src/main/java/conference/Application.java @@ -10,6 +10,12 @@ public class Application { ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class); SpeakerService service = applicationContext.getBean("speakerService", SpeakerService.class); + showObjectAddress(applicationContext.getBean("speakerService", SpeakerService.class)); System.out.println(service.findAll().get(0).getForename()); + showObjectAddress(applicationContext.getBean("speakerService", SpeakerService.class)); + } + + private static void showObjectAddress(SpeakerService speakerService) { + System.out.println(speakerService); } }