Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: overrule PropertyOverrideConfigurer bean in code

  1. #11
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    This works for me (with your configuration from the poc archive you posted):

    Code:
            GenericApplicationContext context = new GenericApplicationContext();
            XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
            reader.loadBeanDefinitions(new ClassPathResource(SPRING_CONTEXT_PATH));
            PropertyOverrideConfigurer cfg = new PropertyOverrideConfigurer();
            cfg.setLocation(new ClassPathResource(ClassUtils.addResourcePathToPackagePath(OverridePropertiesPocTests.class, "dev/overridePropertiesPoc.properties")));
            cfg.setOrder(2);
            context.getBeanFactory().registerSingleton("override", cfg);
            context.refresh();
            PocBean pocBean = (PocBean) context.getBean(BEAN_ID, PocBean.class);
            assertEquals("value from dev properties", pocBean.getName());
    But maybe it should be easier. Remind me: why do you need to do the override programmatically?

  2. #12
    Join Date
    May 2007
    Posts
    8

    Default

    Genius, it works! Thx for the effort.

    We set this programmatically at runtime to reuse the same Spring config for different behaviours.

  3. #13
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    But if all you are doing is switching the location of a properties file at runtime you can do that with a simple PropertyPlaceholderConfigurer?

  4. #14
    Join Date
    May 2007
    Posts
    8

    Default

    The poc example doesn't show the full context of our situation here where several Spring config files come into play. There's already a PropertyPlaceHolder in one of the configs, overriden by a PropertyOverrider in another config and we wanted to override that once more.

    We couldn't change any of the included Spring config files, because they belong to another API.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •