Springboot Integrated AOP (Jointpoint not found)

Source: Internet
Author: User
Tags aop

Springboot Integrated AOP As the example would have been simple, but there could be a hole in the middle of the process.

Come first official standard practice:

The version of my springboot is 1.5.6.RELEASE.

It's OK to add AOP dependencies to Pom.xml:

<dependency>  
      <groupId>org.springframework.boot</groupId>
      <artifactId> spring-boot-starter-aop</artifactid>
      <scope>compile</scope>
    </dependency>

Then you can use it like standard AOP, and here's an example:

@Aspect
@Component Public
class Commonlog {

	private static final Logger Syslogger = Logger.getlogger ( Statedefine.sys_log);

	
	@Pointcut ("Execution" (* org.redstarofsleep.aopsample. *service.* (..)) ")
	public void Service () {};
	
	/**
	 * Description:service method automatically logs when throwing exceptions
	 * @param ex
	/@AfterThrowing (pointcut= "service ()", throwing= ' ex ') public
	void Exceptionofmethod (Joinpoint joinpoint, Exception ex) {
//		Syslogger.error ( Logutil.getexceptions (ex));		Syslogger.error ("* * * ERROR service occurred:", ex);
		Log the exception trace
		syslogger.error ("### error service==========>>" + logutil.getinformation (joinpoint));
        Logutil.logexceptiontrace (ex);
	}

Ben came here to finish it. But this code compiles does not have the error, a start to report jointpoint this class cannot find. Rarely strange.

There may be a problem with this version of the consolidated package, this version of the SPRING-BOOT-STARTER-AOP Consolidated Aspectjweaver version is 1.8.10, replaced by the 1.8 7 problem, so the pom modification is as follows:

<dependency>  
      <groupId>org.springframework.boot</groupId>
      <artifactId> spring-boot-starter-aop</artifactid>
      <scope>compile</scope>
      <exclusions>
      	<exclusion>
      		<groupId>org.aspectj</groupId>
      		<artifactid>aspectjweaver</ artifactid>
      	</exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>  
      <artifactId>aspectjweaver</artifactId>
      <version>1.8.7</version> 
    </dependency>

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.