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?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
This is the point of using a dependency injection framework. The idea is that you simply declare dependencies, the framework connects them. e.g.
You then wire up the framework to inject the B instance into the A. If you get an A from the framework, the B is already provided. There should be no code where you explicitly set the B instance in the A instance.
Look up some references to dependency injection
The canonical approach would be to declare a dependency on the second service in the first one and to just call it.
And configure Spring to wire things together (the core job of Spring) i.e. inject a
Bar
implementation into yourFoo
service.You can call anything from anything else in spring, so long as you have access to the context or bean factory where the services exist. If you don't want to traverse the contexts, you could simply pass the service references to either service in your configuration file.