We are using Struts 2 with spring frame work 4 (https://struts.apache.org/docs/spring-plugin.html). I have some question about Struts bean creation.
When we use Struts with Spring we can easily use spring
Struts uses an
ObjectFactory to build any object like actions, interceptors, validators, etc.:
ObjectFactoryis responsible for building the core framework objects. Users may register their own implementation of the
ObjectFactoryto control instantiation of these Objects.
Struts-Spring plugin registers its own object factory
Struts object factory that integrates with Spring.
There, it overrides methods building Objects, such as
Now if you look at the implementation, it is using method
which generally creates a new instance of the clazz argument.
Central method of this class: creates a bean instance, populates the bean instance, applies post-processors, etc.
Then, the newly created instance is passed for autowiring with
After that, this instance is passed to Guice for injection.
Now it's fully backed and ready to return.
Note that, if the bean is managed by Spring, it uses
getBean method from application context, otherwise the new instance is created always by struts-spring plugin if the bean is not managed by Spring.