Announcement Announcement Module
No announcement yet.
struts integration: are beans not threadsafe? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • struts integration: are beans not threadsafe?

    I'm new to Spring; my first Spring project is using Struts as the web tier.

    Two common options for integrating Spring with Struts, according to the "Professional Java Development with the Spring Framework" book, are:

    1) use the DelegationRequestProcessor class

    2) using an auto wiring base action

    According to the examples in the book, it looks like both these options require the beans to be set as instance attributes in the Struts Action. My concern is that these beans will not be threadsafe (if my understanding is correct, Spring beans can be non-singletons if desired).

    Admittedly it would be desirable in most conceivable models to have a singleton business bean called from the web tier, but equally I think its desirable not to be locked in to this.

    As an alternative, how about a simple getBean() method which could be defined in a BaseAction class (extending ActionSupport) as follows:

    public Object getBean(String beanID) {
    return this.getWebApplicationContext().getBean(beanID);

    Thoughts and replies on this are welcome,



  • #2
    Struts Actions are singletons as well so yes, if you want to have different collaborators you have to issue getBean() calls i use MethodInjection. If you want to use MethodInjection, you have to use the DelegatingRequestProcessor since beans that get methods injected (getCollaborator() for example which returns a new instance per call) have to be defined in a Spring context (and the autowiring approach autowires beans outside the Spring context).

    Hope this helps

    Alef Arendsen