参考書でJava Spring AOPを学習していたところ、エラーが解決できず困っています。
以下のTestAspect.javaの「@Before("execution(* *..ServiceImpl.(..))");」部分に赤色下線でエラー表示が出ておりコンパイルができません。
カーソルを乗せると「ここではアノテーションを使用できません」と表示されます。
IDEはIntelliJ IDEAを使用しています。
@Beforeアノテーションを自動でインポートできたので、ライブラリにはパスが通っていると思います。
詳しい方ご教示いただけますと幸いです。
TestAspect.java
package com.example.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @Aspect @Component public class TestAspect { @Before("execution(* *..*ServiceImpl.*(..))"); public void startLog(JoinPoint jp){ System.out.println("メソッド開始: "+jp.getSignature()); } }
念のためbuild.gradleと環境は以下になります。
build.gradle
plugins { id 'org.springframework.boot' version '2.6.3' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.testng:testng:7.1.0' testImplementation 'org.springframework.boot:spring-boot-starter-test' implementation 'org.aspectj:aspectjweaver' implementation 'org.aspectj:aspectjrt' implementation('org.springframework.boot:spring-boot-starter-aop') implementation('org.springframework:spring-context') implementation('org.springframework:spring-aop') } test { useJUnitPlatform() }
環境
・OS:Ubuntu 20.4、 ・Java:~$ java --version openjdk 11.0.13 2021-10-19 OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.20.04, mixed mode, sharing) ・IDE:IntelliJ IDEA バージョン: 2021.3.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/24 03:55