Spring 带有参数问题的初始化方法
Spring init method with parameters issue
所以我正在学习 spring 依赖注入,并且已经有了 issue.I 两个 classes...一个是 运行 class 另一个是 Builders class.The Builders class 有接受多个参数和returns类型运行[=的对象的静态方法abc 29=]。
它看起来像这样:
public class Run{
private final Check check;
public Run(Check check){
this.check = check;
}
public Check getCheck() {
return check;
}
}
public class Builders {
public static Run abc(multiple arguments) {
Check check = ProxyImplClass.createCheck(multiple arguments);
return new Run(check);
}
}
我只需要在应用程序启动时调用下面提到的语句一次。
运行 运行 = Builders.abc (....接受多个参数....);
我如何使用 spring xml 来做到这一点?如果 class 文件中需要进行一些更改,那么也请提及,因为我对此很陌生Spring 框架。
注意:....abc方法中的多个参数只表示该方法有多个参数。
您可以使用 <bean>
的 factory-method
属性来做到这一点。要使用不同 class 的 static
工厂方法,请使用 class
属性指定包含该方法的 class。
无论您想传递给该方法的什么参数都在 <constructor-arg>
标签中:
<bean id="run" class="pkg.Builders" factory-method="abc">
<constructor-arg type="..." value="...">
<constructor-arg type="..." value="...">
</bean>
所以我正在学习 spring 依赖注入,并且已经有了 issue.I 两个 classes...一个是 运行 class 另一个是 Builders class.The Builders class 有接受多个参数和returns类型运行[=的对象的静态方法abc 29=]。 它看起来像这样:
public class Run{
private final Check check;
public Run(Check check){
this.check = check;
}
public Check getCheck() {
return check;
}
}
public class Builders {
public static Run abc(multiple arguments) {
Check check = ProxyImplClass.createCheck(multiple arguments);
return new Run(check);
}
}
我只需要在应用程序启动时调用下面提到的语句一次。
运行 运行 = Builders.abc (....接受多个参数....);
我如何使用 spring xml 来做到这一点?如果 class 文件中需要进行一些更改,那么也请提及,因为我对此很陌生Spring 框架。
注意:....abc方法中的多个参数只表示该方法有多个参数。
您可以使用 <bean>
的 factory-method
属性来做到这一点。要使用不同 class 的 static
工厂方法,请使用 class
属性指定包含该方法的 class。
无论您想传递给该方法的什么参数都在 <constructor-arg>
标签中:
<bean id="run" class="pkg.Builders" factory-method="abc">
<constructor-arg type="..." value="...">
<constructor-arg type="..." value="...">
</bean>