Announcement Announcement Module
No announcement yet.
Import a spring config.xml file from another? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Import a spring config.xml file from another?

    I have an application that I've recently ported to the spring framework and I'm realizing now that it would be very useful if I could make references to beans in one spring-bean config xml file from another.

    The basic reason is in the (currently solo) config file, most of the configuration is going to be constant, but some is environment specific. If I had two config files I could have one file that is the same across all environments and be able to just swap out the environment specific file when migrating from DEV to QA to PROD etc.

    Is there an import tag available or any such thing? Also, links to usage articles describing this would be greatly appreciated.


  • #2

    Of course there is <import> tag in spring XML config. Check this:

    Also - if you have web application, you can use more than one xml config during initialization:
      <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
    Grzegorz Grzybek


    • #3
      A better approach that I can think of is :-

      1) Separate out your environment specific beans into another config file. Even you infrastructure related bean can be kept in a separate config file
      2) In your environment specific config, use place holder for your environment specific properties. See for more details. This way your application jar/war/ear doesn't have to change when it moves between environments. The property file can be kept in some standard folder like $home/.app/ and will contain the properties for the environment the applications is running in.


      • #4
        import tag is used to import the another xml a resource property is set with path of that xml. benefit is that we can used all beans reference with id or name of imported file in main file-
        file other.xml
                    <bean name="point" class="com.test.Point"></bean>
        file main.xml
                  <import resource="Other.xml"/>
                 <bean id="circle" class="com.test.Circle">
                <property name="p" ref="point"></property>