diff --git a/spring-core-2/src/main/java/com/baeldung/scopes/ScopesConfig.java b/spring-core-2/src/main/java/com/baeldung/scopes/ScopesConfig.java new file mode 100644 index 0000000000..2291baa62d --- /dev/null +++ b/spring-core-2/src/main/java/com/baeldung/scopes/ScopesConfig.java @@ -0,0 +1,49 @@ +package com.baeldung.scopes; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.web.context.annotation.ApplicationScope; +import org.springframework.web.context.annotation.RequestScope; +import org.springframework.web.context.annotation.SessionScope; + +@Configuration +public class ScopesConfig { + + @Bean + @Scope("singleton") + public Person personSingleton() { + return new Person(); + } + + @Bean + @Scope("prototype") + public Person personPrototype() { + return new Person(); + } + + @Bean + @RequestScope + public HelloMessageGenerator requestScopedBean() { + return new HelloMessageGenerator(); + } + + @Bean + @SessionScope + public HelloMessageGenerator sessionScopedBean() { + return new HelloMessageGenerator(); + } + + @Bean + @ApplicationScope + public HelloMessageGenerator applicationScopedBean() { + return new HelloMessageGenerator(); + } + + @Bean + @Scope(scopeName = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS) + public HelloMessageGenerator websocketScopedBean() { + return new HelloMessageGenerator(); + } +}