In Spring Boot 3 for jar-starters now we should use @Autoconfiguration
. @Autoconfiguration
is the @Configuration
with proxyBeanMethods = false
parameter.
In Spring Boot 2 i used the code like this. In singleton component i can create any count of prototype beans.
@Configuration
public class TestPrototypeConfiguration {
@Bean
public SingletonComponent singletoneComponent() {
return new SingletonComponent(this::prototypeComponent);
}
@Bean
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public PrototypeComponent prototypeComponent(int value) {
return new PrototypeComponent(value);
}
}
@RequiredArgsConstructor
public class PrototypeComponent {
private final int value;
}
@RequiredArgsConstructor
public class SingletonComponent {
private final IntFunction<PrototypeComponent> supplier;
public void test() {
for (int i = 0; i < 5; i++) {
supplier.apply(i);
}
}
}
But for Spring boot 3 if I simple change @Configuration -> @Autoconfiguration
the code will start work incorrect. Because when i call supplier
the prototype bean will not construct as spring boot. It will be created as the simple java class.
Can you provide me any suggestion about how to solve this problem, please? Is it possible to solve this problem w/o ApplicationContext.getBean
?