PropertyPlaceholderConfigurer reads from XML File (Apache Commons Configuration)

后端 未结 3 1609
忘了有多久
忘了有多久 2021-02-10 18:51

Is there a possibility to configure the Spring PropertyPlaceholderConfigurer to read from properties.xml, via Apache Commons Configuration?

3条回答
  •  野性不改
    2021-02-10 19:21

    I found a solution with the help of seanizer and springmodule

    
    
        
            
                
                
                    
                
            
        
    
    
    
        
    
    
    
        
    
    

    class TestConfiguration

    public class TestConfiguration {
        private String domain;
        public String getDomain() {
            return domain;
        }
        public void setDomain(String domain) {
            this.domain = domain;
        }
    }
    

    jUnit Testclass

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration( { "/applicationContextTest.xml" })
    
    public class ApacheCommonCfg2Spring extends AbstractJUnit4SpringContextTests {
    
        private TestConfiguration tcfg;
    
        @Test
        public void configuration(){
            tcfg  = this.applicationContext.getBean("testConfig", TestConfiguration.class);
            System.out.println(tcfg.getDomain());
        }
    
    }
    

    Springmodule is rather old an it seems that it is not longer maintained, but it works with Spring 3.0.3.

    feel free to copy & paste!

提交回复
热议问题