Dependency Management in JavaEE and JavaEE dependency management
No matter how great you are, you cannot complete a great task independently. The same is true for the JavaEE component. Without that component, you can complete all tasks independently. When a component is working, it often needs help from other resources. Therefore, the issue of "dependency management" is involved in the process of seeking help. For example, a simple Session bean needs to borrow JDBC data sources for persistent data. For example, a message-driven Bean needs to transmit messages to the JMS message queue. How to obtain resources on the server in components is involved.
Like in real life, you only need to call the phone number if you need fire alarms and policemen to ask 120 for help, but the premise is that you need to know the phone number first. Ing to JavaEE involves many resources in the server. developers need to define referenced resources in the program before using them. The reference to resources in a component can be dynamically parsed from the program code, or automatically parsed by the container when the component is instantiated (dependency injection ?).
A resource reference consists of two parts: the relationship between name and target is similar to the relationship between key and value in json. The previous name is mainly for people to see, the following target is the resources that need to be searched on the server. If you have a name and a target, you need to tell the other party the information if you know the name and target of the police or the phone number of the fire. When the key falls into the house, the fire will know that you want to take the Hydraulic Clamp, when you encounter a gangster, you will know to bring a gun. The official language means that each resource reference requires a set of different information specific to the type of the resource it executes. A reference is usually declared by the following annotations: @ Resource, @ EJB, @ PersistenceContext, or @ PersistenceUnit. Similar to Spring annotations, you can place them in different locations (class, field, or setter method) to determine whether the server will automatically parse (load ).
Next we will introduce different types of dependency types one by one: dependency lookup, dependency injection, and declarative dependency. In essence, they are similar to finding the external resources required by the program through specific information.