2016-11-25 84 views
0

的代码如下接口的Spring bean注入对象

public interface ExperimentConfig { 
    Boolean func1(); 
} 

public class RuntimeConfig implements IntializingBean{ 
    private ExperimentConfig experimentConfig; 

    public ExperimentConfig getExperimentConfig() { 
    return experimentConfig; 
    } 

    public void setExperimentConfig(ExperimentConfig experimentConfig) { 
    this.experimentConfig = experimentConfig; 
    } 
} 

public class Util 
{ 
    public static ExperimentConfig experimentConfig() 
    { 
    return new Builder.build(1,"a",89); 
    } 

的Spring XML文件

<bean id="RuntimeConfig" 
    class="bizconfig.RuntimeConfig"scope="singleton"> 

    <property name="experimentConfig"> 
     <bean class="bizconfig.Util" factory-method="experimentConfig"/> 
    </property> 
</bean> 

此代码dosent似乎工作。当Interface是一个属性时,我认为我使用的是错误的方式。我该如何解决。

+0

什么不起作用? –

回答

1
<bean id="util" class="Util"> 
...properties 
</bean> 

<bean id="RuntimeConfig" 
    class="bizconfig.RuntimeConfig"scope="singleton"> 

    <property name="experimentConfig"> 
     <bean factory-bean="util" factory-method="experimentConfig"/> 
    </property> 
</bean> 
+0

我不以你的意思是“...属性”来表达你的意思。 Util只有静态函数 –

+0

如果你没有任何其他你不需要的属性 – kuhajeyan