Explicitly Define Prototype Bean Scope

master
sgoudham 4 years ago
parent 95422528ac
commit de87a6ad31
No known key found for this signature in database
GPG Key ID: EF51A29A50FB754C

@ -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());
}

@ -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);
}
}

Loading…
Cancel
Save