separate configs

This commit is contained in:
Loredana Crusoveanu
2018-06-24 19:22:26 +03:00
parent fd34932f4c
commit 32a9212fc9
4 changed files with 67 additions and 33 deletions
@@ -3,12 +3,9 @@ package com.baeldung.scope;
import com.baeldung.scope.prototype.PrototypeBean;
import com.baeldung.scope.singletone.SingletonAppContextBean;
import com.baeldung.scope.singletone.SingletonBean;
import com.baeldung.scope.singletone.SingletonFunctionBean;
import com.baeldung.scope.singletone.SingletonObjectFactoryBean;
import com.baeldung.scope.singletone.SingletonProviderBean;
import java.util.function.Function;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -45,19 +42,4 @@ public class AppConfig {
return new SingletonObjectFactoryBean();
}
@Bean
public Function<String, PrototypeBean> beanFactory() {
return name -> prototypeBeanWithParam(name);
}
@Bean
@Scope(value = "prototype")
public PrototypeBean prototypeBeanWithParam(String name) {
return new PrototypeBean(name);
}
@Bean
public SingletonFunctionBean singletonFunctionBean() {
return new SingletonFunctionBean();
}
}
@@ -0,0 +1,32 @@
package com.baeldung.scope;
import java.util.function.Function;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import com.baeldung.scope.prototype.PrototypeBean;
import com.baeldung.scope.singletone.SingletonFunctionBean;
@Configuration
public class AppConfigFunctionBean {
@Bean
public Function<String, PrototypeBean> beanFactory() {
return name -> prototypeBeanWithParam(name);
}
@Bean
@Scope(value = "prototype")
public PrototypeBean prototypeBeanWithParam(String name) {
return new PrototypeBean(name);
}
@Bean
public SingletonFunctionBean singletonFunctionBean() {
return new SingletonFunctionBean();
}
}