Dependency Management in JavaEE and JavaEE dependency management

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.