"Spring Framework"? Perform specific processing and Applicationlistener source analysis at project start-up

Source: Internet
Author: User

1. Background

In some business scenarios, after the container is started, you need to deal with operations such as Kafka business registration, data processing, initializing the cache, and so on.

This article focuses on how to perform related processing when the service starts, or when startup is complete.

2, for the above scenario, like the next implementation method

A: Implement the Javaweb-based Servletcontextlistener interface, overriding the contextinitialized () interface

B: Implement the Filter interface under the Javaweb-based Javax.servlet package, overriding the Init (filterconfig filterconfig) interface

C: Inherit the HttpServlet parent class under Javaweb-based servlet package, overriding the init () interface to

D: Implement spring-based applicationlistener<contextrefreshedevent> interface, rewrite onapplicationevent (contextrefreshedevent Event) interface

Summary: Interfaces based on the Javaweb implementation need to be scanned when web. XML is registered to start. Based on spring implementations, the object needs to be registered in the container.

The following is a loading order in which you can see that listener and filter were executed before the servlet.

3, Applicationlistener Source analysis

You can look at the 78996509 first.

Source analysis on subsequent meeting

"Spring Framework"? Perform specific processing and Applicationlistener source analysis at project start-up

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.