A request scoped bean in spring means that the container create a single bean instance per HTTP request.
Let say I have a RequestScopedBean bean :
@Component
public class RequestScopedBean {
@PostConstruct
void init() {
System.out.println("Init method called for each incoming HTTP Request");
}
}
public void doSomething() {}
Configuration :
@Configuration
public class MyBeansConfig {
@Bean
@Scope(value="request", proxyMode=TARGET_CLASS)
public RequestScopedBean requestScopedBean() {
return new requestScopedBean();
}
}
I'm using my RequestScopedBean inside a Singleton bean - and I'm expecting that the init() method is called for each incoming HTTP request. But it is not. The init() method is called only one time meaning the container create only one instance of my RequestScopedBean !!! Can someone explain to me: if the behavior i'm expecting is correct / or what's wrong with the configuration.