CN111104094A - Method for intercepting program exception and automatically sending mail based on SpringBoot - Google Patents
Method for intercepting program exception and automatically sending mail based on SpringBoot Download PDFInfo
- Publication number
- CN111104094A CN111104094A CN201811267193.1A CN201811267193A CN111104094A CN 111104094 A CN111104094 A CN 111104094A CN 201811267193 A CN201811267193 A CN 201811267193A CN 111104094 A CN111104094 A CN 111104094A
- Authority
- CN
- China
- Prior art keywords
- exception
- mailbox
- sending
- abnormal
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Withdrawn
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/20—Software design
- G06F8/24—Object-oriented
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/302—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q10/00—Administration; Management
- G06Q10/10—Office automation; Time management
- G06Q10/107—Computer-aided management of electronic mailing [e-mailing]
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Business, Economics & Management (AREA)
- General Engineering & Computer Science (AREA)
- Human Resources & Organizations (AREA)
- General Physics & Mathematics (AREA)
- Entrepreneurship & Innovation (AREA)
- Strategic Management (AREA)
- Software Systems (AREA)
- Quality & Reliability (AREA)
- Computing Systems (AREA)
- Tourism & Hospitality (AREA)
- General Business, Economics & Management (AREA)
- Economics (AREA)
- Data Mining & Analysis (AREA)
- Marketing (AREA)
- Mathematical Physics (AREA)
- Computer Hardware Design (AREA)
- Operations Research (AREA)
- Information Transfer Between Computers (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention relates to the technical field of java application and development, in particular to a method for intercepting program exception and automatically sending a mail based on SpringBoot. The method comprises the following steps: 1. defining a global exception handling class; 2. @ ExceptionHandler marks an exception capture entry method; 3. receiving the exception and calling a mail sending method; 4. injecting mailbox account and authorization code information; 5. and sending an abnormal mail. The invention solves the problem that the abnormal information can only be monitored by the server and can not receive the abnormal prompt, and can prompt the abnormal information of the user program by the method of sending the mail.
Description
Technical Field
The invention relates to the technical field of Java application and development, in particular to a method for intercepting program exception and automatically sending mails based on springboot.
Background
The abnormal monitoring is a skill that must be mastered by many operation and maintenance workers or development workers, but the server does not have the function of abnormal reminding, and only can perform abnormal display, so that abnormal information and conditions cannot be monitored in time.
The invention mainly uses a method for intercepting program abnormity and automatically sending mails based on springboot, aims to solve the problems that abnormal information can only be monitored by a server and cannot receive an abnormal prompt, and can prompt the abnormal information of a user program through the method for sending the mails.
Disclosure of Invention
The invention solves the technical problem of providing a method for intercepting program abnormity and automatically sending mails based on springboot; the problem that the abnormal information can only be monitored by the server and cannot be prompted by the abnormality is solved, and the information of the program abnormality of the user can be prompted by a method of sending the mail.
The technical scheme for solving the technical problems is as follows:
the method comprises the following steps:
1. a method for intercepting program exception and automatically sending mail is characterized in that: the method comprises the following steps:
step one, defining a global exception handling class, including a method responsible for capturing and handling global exceptions, and uniformly managing exception behaviors;
step two, realizing a Controller layer exception capture entrance through @ Aspect annotation, and intercepting all exceptions thrown by a Service layer method in Spring;
step three, reserving complete abnormal information in a character printing output stream mode;
step four, setting the sending mailbox as a receiving mailbox, and calling a mailbox sending method to transmit complete abnormal information into the method;
fifthly, reading mailbox account, mailbox port, mailbox host type and authorization code information from the xml file in a Spring injection mode;
and step six, sending the abnormal mail through the javamail.
2. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: in the second step, the abnormal behavior is managed through the AOP section, the regular expression is set through the annotation executed after the abnormal behavior to match the Service layer method needing to be monitored, and the monitored Service layer method can be captured normally when the abnormal behavior occurs.
3. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: the method is characterized in that: in the fourth step, since the purpose is to monitor the abnormality through the mailbox, the sending mailbox is consistent with the receiving mailbox.
4. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: in the fourth step, the completed exception information is the exception information in claim 3, which is obtained by the getMessage method of Throwable in Java.
5. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: in the sixth step, sending the abnormal mail involves the following steps:
(1) creating a message content object;
(2) setting a message coding format;
(3) setting a mail subject;
(4) setting mail content;
(5) setting a receiver mailbox;
(6) the message is sent through javaMailSender.
6. The method of claim 5, wherein the method comprises the steps of: in the step 2, the message encoding format is set to UTF-8 format.
7. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: in the second step, only the Service business logic layer is monitored and intercepted, the Service exception is thrown upwards to the Controller layer, and the exception is intercepted in the throwing process to send and process the mail.
8. The method of claim 5, wherein the method comprises the steps of: in the step 1, the message content object is an object capable of setting a mail subject, mail content and a receiver.
The invention solves the problem that the abnormal information can only be monitored by the server and can not receive the abnormal prompt, and can prompt the abnormal information of the user program by the method of sending the mail.
Drawings
The invention is further described below with reference to the accompanying drawings:
FIG. 1 is a flow chart of the method of the present invention.
Detailed Description
As shown in fig. 1, the present invention specifically comprises the following steps:
1. defining a global exception handling class which comprises a method responsible for capturing and handling global exceptions and uniformly managing exception behaviors;
2. method for marking exception capture entry of @ ExceptionHandler
3. Program receiving exception
4. The complete abnormal information is reserved in a character printing output stream mode;
5. reading mailbox account, mailbox port, mailbox host type and authorization code information from the xml file in a Spring injection mode;
6. and sending the abnormal mail through the javamail.
Claims (8)
1. A method for intercepting program exception and automatically sending mail is characterized in that: the method comprises the following steps:
step one, defining a global exception handling class, including a method responsible for capturing and handling global exceptions, and uniformly managing exception behaviors;
step two, realizing a Controller layer exception capture entrance through @ Aspect annotation, and intercepting all exceptions thrown by a Service layer method in Spring;
step three, reserving complete abnormal information in a character printing output stream mode;
step four, setting the sending mailbox as a receiving mailbox, and calling a mailbox sending method to transmit complete abnormal information into the method;
fifthly, reading mailbox account, mailbox port, mailbox host type and authorization code information from the xml file in a Spring injection mode;
and step six, sending the abnormal mail through the javamail.
2. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: in the second step, the abnormal behavior is managed through the AOP section, the regular expression is set through the annotation executed after the abnormal behavior to match the Service layer method needing to be monitored, and the monitored Service layer method can be captured normally when the abnormal behavior occurs.
3. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: the method is characterized in that: in the fourth step, since the purpose is to monitor the abnormality through the mailbox, the sending mailbox is consistent with the receiving mailbox.
4. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: in the fourth step, the completed exception information is the exception information in claim 3, which is obtained by the getMessage method of Throwable in Java.
5. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: in the sixth step, sending the abnormal mail involves the following steps:
(1) creating a message content object;
(2) setting a message coding format;
(3) setting a mail subject;
(4) setting mail content;
(5) setting a receiver mailbox;
(6) the message is sent through javaMailSender.
6. The method of claim 5, wherein the method comprises the steps of: in the step 2), the message encoding format is set to UTF-8 format.
7. The method for intercepting program exceptions and automatically sending emails according to claim 1, wherein: in the second step, only the Service business logic layer is monitored and intercepted, the Service exception is thrown upwards to the Controller layer, and the exception is intercepted in the throwing process to send and process the mail.
8. The method of claim 5, wherein the method comprises the steps of: in the step 1), the message content object is an object capable of setting a mail subject, mail content and a receiver.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811267193.1A CN111104094A (en) | 2018-10-29 | 2018-10-29 | Method for intercepting program exception and automatically sending mail based on SpringBoot |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811267193.1A CN111104094A (en) | 2018-10-29 | 2018-10-29 | Method for intercepting program exception and automatically sending mail based on SpringBoot |
Publications (1)
Publication Number | Publication Date |
---|---|
CN111104094A true CN111104094A (en) | 2020-05-05 |
Family
ID=70419839
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811267193.1A Withdrawn CN111104094A (en) | 2018-10-29 | 2018-10-29 | Method for intercepting program exception and automatically sending mail based on SpringBoot |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111104094A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111427716A (en) * | 2020-06-10 | 2020-07-17 | 上海冰鉴信息科技有限公司 | Hot plug exception capture method and device based on SpringAop |
CN112488080A (en) * | 2020-12-23 | 2021-03-12 | 武汉烽火众智数字技术有限责任公司 | Fault diagnosis and analysis method and system based on clustering algorithm |
CN114579194A (en) * | 2022-03-08 | 2022-06-03 | 杭州每刻科技有限公司 | Spring remote call-based exception handling method and system |
-
2018
- 2018-10-29 CN CN201811267193.1A patent/CN111104094A/en not_active Withdrawn
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111427716A (en) * | 2020-06-10 | 2020-07-17 | 上海冰鉴信息科技有限公司 | Hot plug exception capture method and device based on SpringAop |
CN112488080A (en) * | 2020-12-23 | 2021-03-12 | 武汉烽火众智数字技术有限责任公司 | Fault diagnosis and analysis method and system based on clustering algorithm |
CN114579194A (en) * | 2022-03-08 | 2022-06-03 | 杭州每刻科技有限公司 | Spring remote call-based exception handling method and system |
CN114579194B (en) * | 2022-03-08 | 2024-04-05 | 杭州每刻科技有限公司 | Exception handling method and system based on Spring remote call |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111104094A (en) | Method for intercepting program exception and automatically sending mail based on SpringBoot | |
US11681697B2 (en) | Method and device for interface operation and maintenance | |
WO2018113385A1 (en) | Method and system for dynamically tracking application of client, client, and server | |
US9158648B2 (en) | Reporting product status information using a visual code | |
PH12018000201A1 (en) | Artificial intelligence based service control and home monitoring | |
CN106485460A (en) | Equipment operation maintenance innovation management system based on cell-phone APP scanning technique | |
CN103490917B (en) | The detection method of troubleshooting situation and device | |
CN110333981B (en) | APP abnormal information feedback method and device and electronic equipment | |
CN111158933A (en) | Distributed transaction processing method and system based on message queue | |
CN110599180B (en) | Vaccine circulation management method and device based on blockchain | |
CN104192660A (en) | Fault alarm Internet-of-Things terminal for maintenance and inspection of elevator | |
CN103269384A (en) | Rich client abnormality processing method, processing device and processing system | |
CN103888346A (en) | Information sending method and information sending device | |
CN109858257B (en) | Access control method and device | |
CN116069838A (en) | Data processing method, device, computer equipment and storage medium | |
CN104944243A (en) | Elevator maintenance testing fault warning internet of things terminal | |
CN114358326A (en) | Household appliance fault processing method, terminal and readable storage medium | |
CN105608518A (en) | Information processing method and apparatus thereof | |
KR20080042630A (en) | Psd ccontrol system in use of mobile device | |
US20150381542A1 (en) | Systems and methods for scheduled delivery of content | |
US20140237110A1 (en) | Server monitoring | |
CN115563089A (en) | Method and system for detecting real-time abnormity of gas station | |
US20100070890A1 (en) | Method for Providing a Manufacturing Execution System (MES) Service to Third Parties | |
CN109743333A (en) | A kind of system of comprehensive analysis enterprise network security loophole | |
CN110750366A (en) | Message processing method and device, computer equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WW01 | Invention patent application withdrawn after publication |
Application publication date: 20200505 |
|
WW01 | Invention patent application withdrawn after publication |