Announcement Announcement Module
Collapse
No announcement yet.
Managing large Spring XML config files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Managing large Spring XML config files

    Hi,

    We have a system that contains fair number of components (~150) all of them are modelled as Spring beans. Then wired up to make the full system.

    To support various customers and products we can create different instance of this subcomponents with different configuration parameters based on their requirements.

    At development phase this worked out quite well. We could Unit test each component.

    But once we put this Live we are facing with the issue of how to manage this large amount of Spring XML files. I will try to give some specific examples.

    (1) Wiring vs Configurable parameters. Wiring of components hardly change. But configurable parameters (eg. host/port/timeouts) can change. And a support personal / system administrator without in-depth knowledge of the application should be able to change configurable parameters.

    How do you separate these two concerns?

    (2) We have taken the decision that each configurable parameter will be defined in the component where it used. (as opposed to some central place then pass on as parameters) This certainly makes the Java code much cleaner, But if you have lots of components you have to change lots of places and there is potential you can miss something.

    So its a bit like you have pushed the problem of managing things from Java to XML!.

    I know this is not really a Spring shortcoming. But I am sure there are people who have used Spring for even larger projects than ours and would have some interesting experiences, insights to share how they approached the problem.

    Any comments / experiences on this is greatly appreciated


    /Roshan

    PS: We are using Spring 1.1.5

  • #2
    Re: Managing large Spring XML config files

    Originally posted by roshang
    (1) Wiring vs Configurable parameters. Wiring of components hardly change. But configurable parameters (eg. host/port/timeouts) can change. And a support personal / system administrator without in-depth knowledge of the application should be able to change configurable parameters.

    How do you separate these two concerns?
    Use a PropertyPlaceholderConfigurer which will read values from property files and apply them to placeholders in the XML. The Spring samples all use this technique.

    Originally posted by roshang
    (2) We have taken the decision that each configurable parameter will be defined in the component where it used. (as opposed to some central place then pass on as parameters) This certainly makes the Java code much cleaner, But if you have lots of components you have to change lots of places and there is potential you can miss something.

    So its a bit like you have pushed the problem of managing things from Java to XML!.
    Not sure I understand what you mean here. There's nothing stopping several components' context files using the same property file location with a PPC as described above..?

    Regards,

    Comment


    • #3
      hi,

      (1) Wiring vs Configurable parameters.
      You can do a lot in this area using org.springframework.beans.factory.config.PropertyP laceholderConfigurer and org.springframework.beans.factory.config.Propertie sFactoryBean. They help to separate application and administration configurations by puting parameters that administrators are normally responsible for into Java properties files and refering them in Spring's configs using ${property} notation (obviously, you can use the same property in any number of cases). Take a look at the javadocs they have some samples there too.

      Comment


      • #4
        Re: Managing large Spring XML config files

        Thanks for the replies.

        (1) The PropertyPlaceholderConfigurer seems like a good solution to separate out admin and wiring stuff. I will give that a shot.

        Has anyone tried managing this from some central repository like a Database? Say if your application is deployed on a clustered environment perhaps you want one central place to manager this. (Instead of having java property files in the filesystem)

        (2) A bit more explanation about "
        So its a bit like you have pushed the problem of managing things from Java to XML!."

        Say you have bean A which uses beans B,C and D. Say all of these beans have configuration parameters say 3 each. You can implement this in 2 ways

        (a) Localized : Define these parameters has field variables in each Bean and use Spring XML to assign the values where the bean is defined. So in this case you will have 3 properties for each bean definition.

        (b) Centralized: Define all the parameters (12) as fields in bean A (the main class for that component). Then pass them as parameters to helper beans B,C and D.

        The centralized approach makes it easier to see what are the configuration parameters for this component and has one central place to view/modify them.

        In the localized approach, the parameters a scattered in the XML. But if you have lots of components and parameters this is a more manageable approach.

        This is similar to a program with good OO principles will use inheritance, overloading etc so you have to look at the whole bunch of classes to understand the behaviour. since there is no central place. But in a programming language like Java using a good IDE like Eclipse or IDEA this is really easy.

        Now if you try the same approach with XML, then I am not aware of any tools that makes this task easy. Spring beandoc is the closest I have seen so far.

        Hope its a bit more clear what I am trying to get at.

        Roshan

        Comment


        • #5
          Re: Managing large Spring XML config files

          Originally posted by roshang
          This is similar to a program with good OO principles will use inheritance, overloading etc so you have to look at the whole bunch of classes to understand the behaviour. since there is no central place. But in a programming language like Java using a good IDE like Eclipse or IDEA this is really easy.

          Now if you try the same approach with XML, then I am not aware of any tools that makes this task easy. Spring beandoc is the closest I have seen so far.

          Hope its a bit more clear what I am trying to get at.
          If I understand what you're driving at, this may help. You can use inheritance in your bean defiitions..
          Code:
          <bean id="a" class="...">
            <property name="foo" value="1"/>
            <property name="bar" value="2"/>
          </bean>
          
          <bean id="b" parent="a">
            <property name="baz" value="3"/>
          </bean>
          So bean 'b' gets its class and the values for 'foo' and 'bar' from those defined in bean 'a' and also defines another property. It could optionally override one of the values obtained from 'a'.

          Chapter 3 of the reference docs should help a lot more with all of this kind of stuff.

          Regards,

          Comment


          • #6
            Re: Managing large Spring XML config files

            Hi,

            Originally posted by davison

            So bean 'b' gets its class and the values for 'foo' and 'bar' from those defined in bean 'a' and also defines another property. It could optionally override one of the values obtained from 'a'.

            Chapter 3 of the reference docs should help a lot more with all of this kind of stuff.
            I am already making use of the bean inheritence. The problem I am facing is with large number of beans the definitions are split over multiple XML files.

            XML File 1: defines bean a
            XML File 2: defines bean b which extends from bean a.
            XML File 3: defines bean c which extends from bean b.

            Now if someone looks at the definition of bean c, its not immediately clear what property values it has. You will have to look at XML files 1 and 2 as well. If you use PropertyOverriding mechanism then that's another place to look at. Imagine doing this on a Live server over a SSH console window!

            Its in light of this I had a look at Spring BeanDoc (which if I am not mistaken your creation Darren). I don't know if that was created for this purpose in mind. But I can see that giving a centeral place to look at the application as a whole and see what values each component is using.

            OK at the moment it doesn't resolve inheritence if they are defined in different XML files (v 0.6.1), but a start.

            Regards,
            Roshan

            Comment


            • #7
              Re: Managing large Spring XML config files

              Originally posted by roshang
              Its in light of this I had a look at Spring BeanDoc (which if I am not mistaken your creation Darren). I don't know if that was created for this purpose in mind. But I can see that giving a centeral place to look at the application as a whole and see what values each component is using.

              OK at the moment it doesn't resolve inheritence if they are defined in different XML files (v 0.6.1), but a start.
              correct, BeanDoc is mostly written by me. How do you link your context files together? If you specify them as separate file inputs to BeanDoc then the consolidated graphs will still show the correct hierarchy, but the individual files will only show the part of the bean defined in that file. However, it will still link to the parent bean definition, so it's only a click away.

              If you use imports (and you'll need to get 0.6.3 from the BeanDoc homepage or a CVS snapshot for this to work) then the inherited beans will be displayed correctly since an import is handled by merging the bean definitions into the importing file as though you'd defined them there in the first place. i.e.
              Code:
              <beans>
                <import resource="classpath&#58;com/foo/file2.xml"/>
                <import resource="classpath&#58;com/foo/bar/file3.xml"/>
              
                <bean id="a" class="..">
                  <property name=".." value=".."/>
                </bean>
              
              </beans>
              Hope that helps,

              Comment


              • #8
                Re: Managing large Spring XML config files

                Hi,

                Originally posted by davison
                If you specify them as separate file inputs to BeanDoc then the consolidated graphs will still show the correct hierarchy, but the individual files will only show the part of the bean defined in that file. However, it will still link to the parent bean definition, so it's only a click away.
                I don't have them as imports. They are passed to the ApplicationContext as a list.

                You are right. I can see them in the consolidated graph. Thanks for your help !.

                Rgds,
                Roshan

                Comment

                Working...
                X