我的项目中有两个spring bean服务类.是否可以从另一个人那里打电话?如果是的话,怎么做?
规范的方法是在第一个服务中声明对第二个服务的依赖,并且只是调用它.
public class FooImpl implements Foo {
private Bar bar; // implementation will be injected by Spring
public FooImpl() { }
public FooImpl(Bar bar) { this.bar = bar; }
public void setBar(Bar bar) { this.bar = bar; }
public Bar getBar() { return this.bar; }
public void doFoo() {
getBar().doBar();
}
}
Run Code Online (Sandbox Code Playgroud)
并配置Spring将事物连接在一起(Spring的核心工作),即将Bar实现注入您的Foo服务.
| 归档时间: |
|
| 查看次数: |
11012 次 |
| 最近记录: |