Announcement Announcement Module
Collapse
No announcement yet.
Inheriting properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inheriting properties

    I have an abstract class which define a map type property which has some values (about two dozen entries). Then, I have four concrete classes that uses the same property but must add their own entries to the map (6-8) and override couple of super class entries.
    If I define the same property in parent and child bean definition XML, will it complement parent class map or override it? I.e. do I need to repeat parent class entries for children or not?
    I certainly can write a test for the case, but if someone knows the answer,
    I'll appreciate it.

  • #2
    The default behavior I believe is child overriding parent, but you can specify merge="true" to make spring combine them.

    Comment


    • #3
      Originally posted by manifoldronin
      The default behavior I believe is child overriding parent, but you can specify merge="true" to make spring combine them.
      How I am suppose to do it?
      I tried to use
      Code:
                  <map merge="true">
      and it failed XML validation. I looked in DTD file and merge attribute appears only in 2.0 which isn't released yet. I can't use it for production system.

      Comment


      • #4
        Ah, sorry, I took it for granted that you were using 2.0.

        Comment


        • #5
          So, is there a way to do this in the 1.X version? Anyone? Anyone?

          Comment


          • #6
            In 1.x there is no out-of-the-box support for this feature. However, you can implement it yourself. If I recall correctly I saw some implementation fragments in the forum.

            The point is to declare the map as standalone bean and refer to it from your parent bean. The child bean then refers to a factory bean which refers to that map and an additional map with the extra values. The responsibility of the factory bean is to do the merge and return the merged map.

            Regards,
            Andreas

            Comment

            Working...
            X