title: Spring - How to cache in self-invocation with aspectJ?
body: <p>Thank you to click my question.
  I want to call a caching method in self-invocation, so I need to use AspectJ.
  (cache's config is okay)</p>
  <ol>
  <li>add AspectJ dependencies</li>
  </ol>
  <pre><code>implementation 'org.springframework.boot:spring-boot-starter-aop'
  </code></pre>
  <ol start="2">
  <li>add @EnableCaching(mode = AdviceMode.ASPECTJ) to my application.java</li>
  </ol>
  <pre><code>@EnableJpaAuditing
  @EnableCaching(mode = AdviceMode.ASPECTJ) // &lt;-- here 
  @SpringBootApplication
  public class DoctorAnswerApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(DoctorAnswerApplication.class, args);
      }
  
  }
  </code></pre>
  <ol start="3">
  <li>my service.java</li>
  </ol>
  <pre><code>@Service
  public class PredictionService {
  
      @Cacheable(value = &quot;findCompletedRecordCache&quot;)
      public HealthCheckupRecord getRecordComplete(Long memberId, String checkupDate) {
          Optional&lt;HealthCheckupRecord&gt; recordCheckupData;
          recordCheckupData = healthCheckupRecordRepository.findByMemberIdAndCheckupDateAndStep(memberId, checkupDate, RecordStep.COMPLETE);
  
          return recordCheckupData.orElseThrow(NoSuchElementException::new);
      }
  }
  </code></pre>
  <ol start="4">
  <li>my test code</li>
  </ol>
  <pre><code>    @Test
      public void getRecordCompleteCacheCreate() {
          // given
          Long memberId = (long)this.testUserId;
          List&lt;HealthCheckupRecord&gt; recordDesc = healthCheckupRecordRepository.findByMemberIdAndStepOrderByCheckupDateDesc(testUserId, RecordStep.COMPLETE);
          String checkupDate = recordDesc.get(0).getCheckupDate();
          String checkupDate2 = recordDesc.get(1).getCheckupDate();
  
          // when
          HealthCheckupRecord first = predictionService.getRecordComplete(memberId,checkupDate);
          HealthCheckupRecord second = predictionService.getRecordComplete(memberId,checkupDate);
          HealthCheckupRecord third = predictionService.getRecordComplete(memberId,checkupDate2);
  
          // then
          assertThat(first).isEqualTo(second);
          assertThat(first).isNotEqualTo(third);
      }
  </code></pre>
  <p>What did I don't...?
  I didn't make any class related with aspectJ.
  I think <code>@EnableCaching(mode = AdviceMode.ASPECTJ)</code> make @Cacheable work by AspectJ instead Spring AOP(proxy).</p>