我有一個spring.xml 如下
<beans xmlns=......">
<bean id="OutputHelper" class="com.mkyong.output.OutputHelper">
<property name="outputGenerator" ref="CsvOutputGenerator" />
</bean>
<bean id="CsvOutputGenerator" class="com.mkyong.output.impl.CsvOutputGenerator" />
<bean id="JsonOutputGenerator" class="com.mkyong.output.impl.JsonOutputGenerator" />
</beans>
想要改為javaConfig
如下
@Configuration
public class AppConfig {
@Bean(name="csvOutputGenerator")
public CsvOutputGenerator csvOutputGenerator() {
return new CsvOutputGenerator();
}
@Bean(name="jsonOutputGenerator")
public JsonOutputGenetator jsonOutputGenerator() {
return new JsonOutputGenetator();
}
@Bean(name="outputHelper")
public OutputHelper outputHelper() {
return new OutputHelper();
}
}
OutputHelper.java 如下
public class OutputHelper
{
IOutputGenerator outputGenerator;
public void setOutputGenerator(IOutputGenerator outputGenerator){
this.outputGenerator = outputGenerator;
}
}
但是 <property name="outputGenerator" ref="CsvOutputGenerator" />
不知道要怎麼改?
謝謝~