Home > Back-end > Automatic configuration file for SpringMVC is how to interface to assign an implementation class?
Automatic configuration file for SpringMVC is how to interface to assign an implementation class?
Time:09-25
Before the said specific content, it is necessary to first explain the Spring (not subset for SpringMVC) configuration file dependency injection to understand: In the configuration file is equivalent to write a certain object in advance all the implementation class, is quite so a tree like this:
That is when I want to use these objects need to first create a top-level objects (that is, the IOC container), which is ApplicationContext implementation class can hold objects, when to use these objects will need to be taken out by the IOC container,
Said then see for SpringMVC and create a container to hold the object and then taken out with specific meaning is in a class, an example here is this an annotation for the service class, then there is the reference of the interface (properties or fields or global variable), there is no initialization, which is directly declare a variable (reference) here, like this:
Test Test;
Then in the configuration file dependency injection way to write the bean implementation class label, just started to use directly,
CodePudding user response:
Specific want what to ask?
CodePudding user response:
Bean is not necessarily a tree in a container, they are a bunch of objects, can have a relationship, can also has nothing to do, Bean initialization may not be the vessel when instantiated, if configured as lazy loading, only at the time of use the bean he will instantiate, Usually only an implementation of an interface, this time the container which is easy to derive instantiation, Have multiple implementation classes or specify the implementation class XML configuration, @ Autowire either when the Qualifier is specified,