Announcement Announcement Module
Collapse
No announcement yet.
Import a spring config.xml file from another? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    Thanks.

  • #2
    Hi

    Of course there is <import> tag in spring XML config. Check this: http://static.springsource.org/sprin...ory-xml-import.

    Also - if you have web application, you can use more than one xml config during initialization: http://static.springsource.org/sprin...ontext-create:
    Code:
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
    </context-param>
    regards
    Grzegorz Grzybek

    Comment


    • #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 http://static.springsource.org/sprin...lderconfigurer 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/config.properties and will contain the properties for the environment the applications is running in.

      Comment


      • #4
        import tag is used to import the another xml file.here 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-
        Code:
        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>
                </bean>

        Comment

        Working...
        X