Dependency injection and the bean scope
We understand each scope has a different boundary. Now, we will write one REST controller to understand how different scope beans are injected to other reference beans by writing simple Spring boot applications.
In the following diagram, the StudentController has injected the reference to all other classes. The ClassDetail
class with the session
scope has two references to singleton and prototype, and the student application contains a few other associations between classes as well. Autowired annotation is utilized to fulfill dependency between beans. Just to clarify, Spring controllers are always created with the singleton scope:
As we are writing a Spring boot application with REST. Will will have to create a maven project and the configuration of pom.xml
file would be:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http...