'Where exactly are spring beans used? Looking for help understanding spring beans in depth
I'm using spring MVC and was hoping to understand the concept a bit better. I have been through some videos, samples and the spring Beans/IoC documentation but it's still not completely clear. I understand the basic idea behind it, but not where / how it is used exactly.
Asumming the example below (from this repo) where is the Bean later used? What is done by Spring Container 'in the background'? I can't see it behing used again in the rest of the sample (within that repo). Maybe anyone could shed some light as wo where exactly this bean is being used and / or what happens in the background. Many thnaks.
@Bean
public RouterFunction<ServerResponse> routerFunction(){
return RouterFunctions.route()
.GET("/router/customers",handler::loadCustomers)
// Some more routes
.build();
}
Solution 1:[1]
Beans are just to model your scenario. When you are trying to write a java program means you are trying to solve a real world problem in software aspect. For that first you need to model the problem in the application domain. Beans help you out there. Spring wire up the things loosely, I would say. things change often, Spring supports the change easily. If you strict the connections and combinations with Java, you have much hard work to do in a change.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Chege Nganga |