Spring 4.x Sensing interface

Source: Internet
Author: User

1 Applicationcontextaware

Provides an applicationcontext reference to an instance when a applicationcontext creates an instance that implements the Org.springframework.context.ApplicationContextAware interface.

Public interface Applicationcontextaware {

void Setapplicationcontext (ApplicationContext applicationcontext) throws beansexception;


So beans can programmatically manipulate the creation of their applicationcontext, either through the ApplicationContext interface or through a transformation referred to as the known subclass of the interface, such as the configurableapplicationcontext of the extra function of the storm drain. We can retrieve other beans programmatically. Sometimes this ability is useful, however, usually you should avoid it because it bundles the spring code and does not conform to the style of inversion of control. ApplicationContext provides other ways to access file resources, publish app events, and access Messagesource.

Starting with spring 2.5, auto-injection is another option for getting applicationcontext references. The "traditional" constructor and bytype auto-injection patterns provide a applicationcontext type of dependency injection for constructor parameters or setter method parameters. More flexibility, including the ability to automatically inject fields and multiple parameter methods, using the new annotation-based auto-injection feature. If you do this, ApplicationContext can be automatically injected into a field, constructor parameter, or method parameter.

2 Beannameaware

When a applicationcontext creates a class that implements the Org.springframework.beans.factory.BeanNameAware interface, the container provides a bean name for the class for the class.

Public interface Beannameaware {

void Setbeanname (String name) throws Beansexception;


Called after the normal bean property is populated, but before the initialization callback (Initializingbean's Afterpropertiesset method or custom Init-method method).

3 Other Perceptual interfaces

In addition to Applicationcontextaware and Beannameaware,spring, a series of aware interfaces are supported, allowing beans to tell the container that they require an infrastructure dependency. Most of the important aware interfaces are summarized below--in general, names are good representations of dependent types:

Table Aware Interface

Dependency Injection
Statement ApplicationContext
Event publishers who encapsulate ApplicationContext
Beanclassloaderaware class loader for loading bean classes
Beanfactoryaware Statement Beanfactory
Beannameaware Declaring the Bean's name
Bootstrapcontextaware The resource adapter Bootstrapcontext is running in the container. Usually valid only in JCA-aware ApplicationContext
Loadtimeweaveraware Defines the weaver in the load time processing class definition
Messagesourceaware Parsing the configuration policy for messages (provides parameterization and internationalization)
Notificationpublisheraware Spring JMX Notification Publisher
Portletconfigaware The portletconfig that the current container is running. Valid only in web-aware spring ApplicationContext
Portletcontextaware The portletcontext that the current container is running. Valid only in web-aware spring ApplicationContext
Resourceloaderaware Configuration loader for underlying access resources
Servletconfigaware The servletconfig that the current container is running. Valid only in web-aware spring ApplicationContext
Servletcontextaware The ServletContext that the current container is running. Valid only in web-aware spring ApplicationContext

Again, note that the code that uses these interfaces is bundled with the Spring API and does not conform to the control reversal style.

Spring 4.x Sensing interface

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.