Announcement Announcement Module
Collapse
No announcement yet.
Token replacement or similur Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Token replacement or similur

    Hi,

    Is it possible to have some kind of token replace in the spring configuration files. As an example we start with a different configuration file for development and production with some basic differences in this files, such as the DataSource. We then include files that are the same for both environments using the <import> tag.

    However, we now have some need for something to change in these detail files for the different environments. We could include deferent files for each environment but that would mean the included files would be identical except for one property.

    Some kind of token definition in file 'A' that can then be used in the included file 'B' would be ideal.

    Any ideas?

    Scott

  • #2
    Sounds like you want PropertyPlaceholderConfigurer.
    http://www.springframework.org/docs/...lderconfigurer

    Comment


    • #3
      I saw that capability but was hoping there was something that could be done just in the spring configration files, I.E., not have to have a seperate property file.

      Comment


      • #4
        Actually in reading the Java doc it looks like default properties can be set. That might work. Let me try it.

        Comment


        • #5
          If you could post back either way that would be good. I'm just trying to understand the details of what you are trying to do.

          Comment


          • #6
            I did get this working using the following:

            xml in our main spring conf file: There would be one of these for production, development, staging, etc.

            <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
            <property name="properties">
            <props>
            <prop key="default_schema">ADVJPMT</prop>
            </props>
            </property>
            </bean>

            We have a separate hibernate configuration file that creates the session factories. You can use the token generated above in there as so: That way we don't have to have seperate ones for production, etc.

            <property name="hibernateProperties">
            <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.DB23 90Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.lazy">true</prop>
            <prop key="hibernate.default_schema">${default_schema}</prop>
            </props>
            </property>

            We don't use ApplicationContext so we must manually instantiate the bean:

            PropertyPlaceholderConfigurer pc = (PropertyPlaceholderConfigurer) beanFactory.getBean("propertyConfigurer");

            pc.postProcessBeanFactory((ConfigurableListableBea nFactory) beanFactory);

            Scott

            Comment

            Working...
            X