Results 1 to 2 of 2

Thread: Injecting a property set into an application

  1. #1
    Join Date
    Oct 2005
    Posts
    23

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    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
    Chris Harris
    Carlisle, UK

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •