
> 2025-03-13T14:58:59.759+09:00 ERROR 18996 --- [ main] o.s.b.web.embedded.tomcat.TomcatStarter :
Error starting Tomcat context.
Exception:
org.springframework.beans.factory.UnsatisfiedDependencyException. Message:
Error creating bean with name 'filterConfig' defined in file
파일경로 : Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name
'jwtUtil': Invocation of init method failed ```
저번과 같은 에러로, jwt secret key 가 없기 때문에 실행이 안된다는 뜻.
다운 받은 프로젝트에 *.properties 파일이 없음.
.gitignore 에 보안상 application.properties를 올려선 안되므로,
*.properties 를 추가했기 때문이다.

application.properties 추가 후
secret key 생성 후 추가
터미널 명령어: HS256, Base64인 경우
openssl rand -base64 64

queryDsl 환경설정에서 뭔가가 잘못됐는지 계속 잘못된 경로라고 에러가 뜸.
error: Attempt to recreate a file for type org.example.expert.domain.common.entity.QTimestamped

튜터님 도움으로 해결

우선 오른쪽 Gradle - build - clean 으로 build에 있는 파일들을 모두 지우고,
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
build.gradle 파일에서 쓸데없는 querydsl 코드 모두 지운 뒤 저 위에 것만 붙이니까 해결.
내가 블로그에서 잘 모르고 이것저것 환경변수를 모두 추가하는 바람에 생긴 문제였다.ㅠㅠ
❗그리고 에러는 맨 마지막 줄에서 발생하므로, 그것부터 해결할 것

jwtFilter 에서 Spring Security 필터로 교체.
로그인할 때 필요한 AuthUser 객체가 null이기 때문에, 생긴 에러.
원래는 사용자 커스텀 어노테이션 @Auth 로 AuthUser 객체 정보를 받았으나,
secrity 내장 어노테이션 @AuthenticationPrincipal 로 하면 좀 더 간편하다 해서 시도해 봄.
AuthUser 에 implements UserDetails 추가하면 passwordEncorder도 내장 메소드로 알아서 작동한다.
그리고, authUser에 저장이 안된 이유는 허무했는데, common 패키지의 AuthUser와 User 패키지의 AuthUser 경로가 꼬여서인 것.
경로를 고치니 간단히 해결.
해결과정은 log로 계속 ROLE_USER 객체의 행방을 찾아서 해결.
경로가 다르기 때문에 처음에 입력된 role값에는 객체가 있지만 나중에 뜬 role값에는 객체가 없다.
Description:
Parameter 0 of constructor in org.example.expert.config.JwtAuthenticationFilter required a bean of type 'org.example.expert.config.JwtUtil' that could not be found.
Action:
Consider defining a bean of type 'org.example.expert.config.JwtUtil' in your configuration.```
기존에 잘 됐던 todo 생성controller test Code에서 이런 에러가 뜸.
jwtUtil bean 이 생성이 안됐다고 함.
원래도 jwtToken은 필요했었는데 왜 security filter를 추가하니 이런 에러가 걸리는지 모르겠지만, 어쨌든 mock 객체 추가.
@MockBean
private JwtUtil jwtUtil;
이것만으로는 안돼서 이것저것 시도하다 결국 튜터님 도움을 받음.
@Test
@WithMockUser(username = "testuser", roles = "USER")
void todo단건조회에_성공한다() throws Exception {
저 @WithMockUser 가짜 유저 정보를 추가하니 성공
튜터님이 필터 설정을 끄는 방법도 있다고 했는데, 이부분은 주말에 조사해봐야겠다.
List<TodoFindResponse> todoList = jpaQueryFactory
.select(new QTodoFindResponse(todos.title, managers.count(), comments.count()))
.from(todos)
.join(todos.comments, comments)
.join(todos.managers, managers)
.join(managers.user, users)
.where(users.nickname.like("%" + nickname + "%"))
.groupBy(todos.id)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();``````
코드를 입력하세요
projections를 적용하라는 과제 요구사항에 따라 위와 같은 쿼리문을 작성했는데,
결과가 엉망으로 나옴.
시도하다 튜터님 도움을 받았는데, SQL문 기초적인 문제였다.
groupBy로 id를 묶는 경우는 select에도 id를 추가해주기.
List<TodoFindResponse> todoList = jpaQueryFactory
.select(new QTodoFindResponse(todos.id, todos.title, managers.countDistinct(), comments.countDistinct()))
.from(todos)
.leftJoin(todos.managers, managers)
.leftJoin(todos.comments, comments)
.where(todos.createdAt.between(startDate, endDate))
.groupBy(todos.id)
.orderBy(todos.createdAt.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();```
그리고 join할 때 comment 개수 결과에서 comment 수 *manager 수 가 결과로 나오는 문제도 발생.
이건
managers.count(), comments.count() ->
managers.countDistinct(), comments.countDistinct()
로 해결.