【发布时间】:2011-10-28 12:48:22
【问题描述】:
我正在编写一个客户端/服务器应用程序并使用 Spring 对其进行配置。
我的客户端界面处理对服务器的编组请求并处理响应。
目前,我有一个看起来像这样的工厂:
public class ClientFactory {
private ApplicationContext ctx;
public ClientFactory(){
ctx = new AnnotationConfigApplicationContext(MyConfig.class);
}
public MyClient(String host, int port){
MyClient client = ...
// create a connection to the server
return client;
}
}
现在,MyClient 有一堆我想注入的依赖项,所以我想使用 Spring 创建 MyClient 实例并使用 @Inject 注解来注入依赖项。
如何将主机/端口作为配置元数据传递到 Spring 配置中?如果我不能,推荐的替代方案是什么。我可以自己完成所有的接线,但这就是 Spring 的用途。
杰夫
【问题讨论】:
标签: java spring dependency-injection factory