AOP SpringConfig @Bean으로 등록시 에러
951
16 asked
밑의 질문에 참고했는데 저는 다른 에러가 떠서 질문에 남깁니다.
전 import hello.hellospring.aop.TimeTraceAop 까지는 잘되어 있는데
빌드 시에는 package hello.hellospring.aop does not exist로 에러가 떠서 구글에 찾으려해도 어떻게 접근을 해야할지 몰라 곤란하네요 ㅠㅠ
package hello.hellospring;
import hello.hellospring.aop.TimeTraceAop;
import hello.hellospring.repository.MemberRepository;
import hello.hellospring.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
@Configuration
public class SpringConfig {
DataSource dataSource;
private EntityManager em;
private final MemberRepository memberRepository;
@Autowired
public SpringConfig(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}
// @Autowired
// public SpringConfig(EntityManager em) {
// this.em = em;
// }
// @Autowired
// public SpringConfig(DataSource dataSource) {
// this.dataSource = dataSource;
// }
@Bean
public MemberService memberService() {
// return new MemberService(memberRepository());
return new MemberService(memberRepository);
}
// @Bean
// public MemberRepository memberRepository() {
// // return new MemoryMemberRepository();
// // return new JdbcMemberRepository(dataSource);
// // return new JdbcTemplateMemberRepository(dataSource);
// // return new JpaMemberRepository(em);
// }
@Bean
public TimeTraceAop timeTraceAop() {
return new TimeTraceAop();
}
}
package hello.hellospring.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Aspect
public class TimeTraceAop {
@Around("execution(* hello.hellospring..*(..)) && !target(hello.hellospring.SpringConfig)")
public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
System.out.println("Start : " + joinPoint.toString());
try {
return joinPoint.proceed();
} finally {
long finish = System.currentTimeMillis();
long timeMs = finish - start;
System.out.println("End : " + joinPoint.toString() + " " + timeMs + "ms");
}
}
}
Answer 7
2
SeongBaek CHO님 폴더에 들어가서 확인해보니 파일 이름이
TimeTraceAop.aj로 되어 있었습니다. TimeTraceAop.java로 변경하시면 될꺼에요^^
아마 IntelliJ에서 생성할 때 apetcj로 생성하신듯요.
변경하고 실행하니 잘 동작합니다^^
즐거운 주말 되세요
0
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'hello'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
compileOnly("org.springframework.boot:spring-boot-devtools")
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
..
0
74
2
Unused property.....
0
98
2
project JDK is misconfigured
0
130
2
외부 API의 ID 타입(String/UUID)과 내부 도메인의 ID 타입(Long)이 불일치할 때의 설계 정석
0
82
2
단위/통합 테스트 버전충돌 문제
0
91
2
❗️springboot 4.0.2 버전 aspectj dependency 설정❗️
0
228
1
왜 컨트롤러는 변한게 없는데 새로 만든 html 파일이 뜨나요?
0
101
2
윈도우 build test오류 질문
1
102
2
테스트 관련 공부에 대한 조언을 얻고 싶습니다
0
98
2
테스트 실행 시 에러 질문
0
289
1
name을 통한 비교와 객체를 통한 비교
0
77
1
빌드 후 libs 없음
1
128
1
윈도우 gradlew.bat 에러
0
167
1
@PostMapping("/members/new")가 동작하지 않습니다
0
88
1
java static class와 kotlin class
0
77
1
스프링 DB연결
0
126
1
소요 시간
0
85
2
ddl.sql에 빨간 밑줄
1
101
2
welcome page 에러
0
180
3
잘 모르겠습니다.
0
163
2
fail을 똑같이 쳤는데 오류가 발생해요
0
156
2
index.html Welcome page
0
120
1
프로젝트 gradle-groovy ?
0
364
1
테스트코드 메서드명 한글
0
199
2


