2016-12-27 8 views
1

ZookeeperからプロパティをロードするためのFactoryBeanyの作成。 XMLを使用している間 PropertySourcesPlaceholderConfigurerの参照としてのSpring FactoryBean

public class ZkPropertiesFactoryBean extends AbstractFactoryBean<Properties> {..} 

は私が
@Bean 
    public static PropertySourcesPlaceholderConfigurer loadProperties() throws Exception { 
     PropertySourcesPlaceholderConfigurer prop = new PropertySourcesPlaceholderConfigurer(); 
     prop.setIgnoreUnresolvablePlaceholders(true); 
     return prop; 
    } 

何ですかPropertySourcesPlaceholderConfigurer

を使用して、JavaのコンフィグにXML設定を変換しようとしている

<bean id="zkProperties" class="test.ZkPropertiesFactoryBean"/> 
<context:property-placeholder properties-ref="zkProperties"/> 

を次のようにBeanを参照することが可能であるconfigコンproperties-refに相当しますか?私は同じことをするための参照を見つけることができません。

答えて

1

あなたはPropertySourcesPlaceholderConfigurersetPropertiesを使用して、あなたのAbstractFactoryBean.getObject()メソッドを使用して、それを設定することができます。

のようなものになりますあなたの設定:

@Configuration 
    public class ZookeeperConfig { 

     @Autowired 
     private ZkPropertiesFactoryBean zkPropertiesFactoryBean; 

     @Bean 
     public static PropertySourcesPlaceholderConfigurer loadProperties() throws Exception { 
      PropertySourcesPlaceholderConfigurer prop = new PropertySourcesPlaceholderConfigurer(); 
      prop.setIgnoreUnresolvablePlaceholders(true); 
      prop.setProperties(zkPropertiesFactoryBean.getObject()); 
      return prop; 
     } 
    } 
関連する問題