1. 程式人生 > >spring aop Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: 報錯

spring aop Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: 報錯

       最近這幾天在公司研究spring aop(面向切面程式設計),在使用spring 註解實現時,遇到了一個bug,由此記錄一下,方便日後讀閱;報錯如下圖所示:

  由於是第一次接觸spring aop 當時就懵逼了,在網上搜索相關的錯誤,最後找到了自己的問題出在哪裡;

 我這裡出錯的原因是因為在使用註解定義切面物件的切入點時,沒有使用spring aop中的 execution()的表示式導致出現這樣的錯誤,一開始的程式碼如下:紅色部分出錯

@Aspect
// 宣告該類是切面類
@Component
// 配置檔案中啟動自動掃描功能,將該切面交給spring 去管理
public class Transaction {

  // 定義切點
  @Pointcut(" com.bjsd.aop.service.*.*(..)")
  public void allMethod() {
  };
/** * 在核心業務執行前執行,不能阻止核心業務的呼叫。 * * @param joinPoint */ @Before("allMethod()") private void doBefore(JoinPoint joinPoint) { System.out.println("-----doBefore().invoke-----"); System.out.println(" 此處意在執行核心業務邏輯前,做一些安全性的判斷等等"); System.out.println(" 可通過joinPoint來獲取所需要的內容"); System.out.println("-----End of doBefore()------"); } }
     修改方法:在使用註解定義切入點時要使用execution()表示式去匹配我們程式中的哪個包中的哪個類的哪個方法被定義為切入點。

 修改後的程式碼:
 

@Aspect
// 宣告該類是切面類
@Component
// 配置檔案中啟動自動掃描功能,將該切面交給spring 去管理
public class Transaction {

  // 定義切點
  @Pointcut("execution(* com.bjsd.aop.service.*.*(..))")
  public void allMethod() {
  };

  /**
   * 在核心業務執行前執行,不能阻止核心業務的呼叫。
   * 
   * @param joinPoint
   */
   @Before("allMethod()")
   private void doBefore(JoinPoint joinPoint) {
   System.out.println("-----doBefore().invoke-----");
   System.out.println(" 此處意在執行核心業務邏輯前,做一些安全性的判斷等等");
   System.out.println(" 可通過joinPoint來獲取所需要的內容");
   System.out.println("-----End of doBefore()------");
   }
}
   最後問題解決;哪位朋友有不同的見解,歡迎留言,大家共同進步!

相關推薦

spring aop Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed:

       最近這幾天在公司研究spring aop(面向切面程式設計),在使用spring 註解實現時,遇到了一個bug,由此記錄一下,方便日後讀閱;報錯如下圖所示:   由於是第一次接觸spring aop 當時就懵逼了,在網上搜索相關的錯誤,最後找到了自己的問題出

spring aop定義增強時候 Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expec

Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 11 Caused by: java.lang.IllegalArg

AOP異常一:Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

切入點引數定義錯誤:發現是因為在 配置檔案 中對進行要攔截的方法引數的注入。 也就是說,如果你要攔截的方法中有引數,那麼在配置檔案的aspect的expression中也需要有 and args(methodName)。 舉我編寫的例子: package com.zrk

Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

 切入點引數定義錯誤  錯誤詳細資訊如下,紅色標註是錯誤的關鍵點 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IStudentMgr'

Spring整合mybatis:Caused by: java.lang.IllegalArgumentException錯誤

java.lang.IllegalArgumentException     at org.springframework.asm.ClassReader.<init>(Unknown Source)     at org.springframew

Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nes

springboot Caused by: java.lang.IllegalArgumentException: Property 'sessionFactory' is required

異常資訊:springboot Caused by: java.lang.IllegalArgumentException: Property 'sessionFactory' is required 一般出現該類問題就是配置的問題,無論是xml配置。還是springboot的yml配置。

Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value

整合spring+mybatis 報錯以下錯誤: 我完全是IDEA的問題!!!找了半天啊!!! org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.wechat.mo

Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

前言:最近在寫一個oa專案,用的是ssh框架,使用註解開發啟動tomcat的時候報了下面錯誤 問題: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'depa

tomcat啟動Caused by: java.lang.IllegalArgumentException: The main resource set specifiedis not valid

原因:筆者電腦中不存在“G:\Tomcatdata\data\sourcecode\chapter03\helloapp]”此路徑、檔案,所以刪除tomcat檔案目錄下的conf\server.xml檔案中的對應資訊(Context)後,tomcat能正常啟動。 錯誤資訊如下:

Caused by: java.lang.IllegalArgumentException: argument type mismatch

essage Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.

[異常]Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for

Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for at org.apache.ibatis.session.Configuration$St

Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotat

spring boot】【elasticsearch】spring boot整合elasticsearch,啟動Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], reje

  spring boot整合elasticsearch, 啟動報錯: Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8] at

Caused by: java.lang.IllegalArgumentException: Could not locate call adapter for rx.Observable錯誤

public class TRService { public static final String BASE_TRC_URL = "http://www.tuling123.com/openapi/"; private static Retrofit

解決Caused by: java.lang.IllegalArgumentException: Property sqlSessionFactory or sqlSessionTemplate ar

啟動tomcat之後日誌裡面報:Caused by: java.lang.IllegalArgumentException: Property sqlSessionFactory or sqlSessionTemplate are required, 網上看了一些文章,基本上是少了:

Caused by: java.lang.IllegalArgumentException: argument type mismatch錯誤

2014-06-24 08:51:42,984 ERROR [main] (DefSchedulerEngine.java:157) - 排程引擎啟動異常 org.springframework.orm.hibernate3.HibernateSystemException

Caused by: java.lang.IllegalArgumentException android.os.Parcel.readException(Parcel.java:1687)

java.lang.RuntimeException: Unable to resume activity {com.android.soundrecorder/com.android.soundrecorder.SoundRecorder}: java.lang.Ill

Caused by: java.lang.IllegalArgumentException: Negative time

問題 最近在部署war應用的時候,出現如下錯誤: Caused by: java.lang.IllegalArgumentExce

Spring Boot 整合 log4j 實現日誌管理java.lang.IllegalArgumentException: LoggerFactory is not a Logback

問題: Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Log