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,

CodePudding user response:

reference 1st floor abcdefghiijklmnopqrs response:
specific want what to ask?

A Service layer in the class, it has an attribute, this property is just a statement but uninitialized, then when the program calls did not see have the action of initialization, however, direct use in the (that is to give it a specific object), don't know why I will give it, probably is such a problem, how do you get this object? See only write the configuration file contains the entity object, didn't see the process of create a container (this is why the first said Spring, because Spring out object also see new a container), which is out from the container to it, if it is written on the notes of a statement AutoWire, and assign the implementation class Rep... Warehouse annotations, this also can understand, because this kind of blunt point is automatically injected from labeled Rep found in warehouse annotation class "with type" object and created for this variable, and is the main problem is that:
1. Configuration file writing object, is to create the object, the object of the entity class is the
2. Don't see that create containers out implementation object

Exactly how the object was to give the property?

CodePudding user response:

Such as you are in a class mark @ service such annotations, configuration in the sping the packages can be to scan the tags automatically annotated classes, sping will scan and create an object, through reflection sping the container store has a key/value pair data structure (the key is if not specified on the annotation is the class name of the first letters lowercase, value is the reflection to create objects), there is a service in the controller class attribute, this property added @ Autowire annotations, sping in its class management will find inside container and property key name in the name of the object is assigned to this attribute

CodePudding user response:

Is for springMVC conducts file operations in what are the classes and interfaces?
  • Related