Announcement Announcement Module
Collapse
No announcement yet.
Injecting a property set into an application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injecting a property set into an application

    Hi,

    Here's the problem I am facing. I have a set of properties (in a proprietary xml format) which I want to make available to all controllers in my web application. The strategy I would like to use is the following:
    1. Define a bean which is responsible for reading the xml file and transforming it into a set of properties (propertySetBean)
    2. Have all of my controller classes extend a base class which exposes a property to set this property set bean (BaseControllerClass)
    3. Inject the propertySetBean into each controller I am defining

    I see two problems with this approach:
    1. If all of my controllers have to extend from this base class I won't be able to use any of the predefined controllers Spring comes with
    2. I don't like the idea of repeatedly injecting the property set into each controller I am defining. I would like to inject it once and be done with it.

    Any other ideas? I am pretty new to spring, I may have missed some obvious features, so anything is welcome.
    Thanks

  • #2
    If all of my controllers have to extend from this base class I won't be able to use any of the predefined controllers Spring comes with
    You can extend one of Spring's controllers, e.g. SimpleFormController, as you suggest, and extend that for individual purposes.

    I don't like the idea of repeatedly injecting the property set into each controller I am defining. I would like to inject it once and be done with it.
    You can set up a template:
    Code:
    <bean id="myTemplate">
        <property name="myProperties" ref="myPropertiesBean">
    </bean>
    and use this as a parent for your controllers:
    Code:
    <bean id="myFirstController" class="xxx.yyy.zzz" parent="myTemplate">
        . . . all the properties unique to this controller . . .
    </bean>
    HTH

    Comment

    Working...
    X