I have two spring bean Service classes in my project. Is it possible to call one from another? if yes, how it can be done?
I have two spring bean Service classes in my project. Is it possible to call on from another? if yes, how it can be done?
The canonical approach would be to declare a dependency on the second service in the first one and to just call it.
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();
}
}
And configure Spring to wire things together (the core job of Spring) i.e. inject a Bar
implementation into your Foo
service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With