강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

Jiwon님의 프로필 이미지
Jiwon

작성한 질문수

스프링 핵심 원리 - 고급편

템플릿 메서드 패턴 - 예제3

Slf4j log 관련 오류

작성

·

418

0

[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예)

[질문 내용]
 
안녕하세요 영한님 항상 좋은 강의 감사드립니다.
 
templateMethodV2 를 작성하는 과정에서 오류가 발생했습니다.
'log' has private access in 'com.example.advance.template.code.AbstractTemplate'
위와 같은 컴파일 오류인데요
 
제 코드는 아래와 같습니다
package com.example.advance.template;

import com.example.advance.template.code.AbstractTemplate;
import com.example.advance.template.code.SubclassLogic1;
import com.example.advance.template.code.SubclassLogic2;
import org.junit.jupiter.api.Test;

public class TemplateMethodTest {

@Test
void templateMethodV1() {
AbstractTemplate template1 = new SubclassLogic1();
template1.execute();

AbstractTemplate template2 = new SubclassLogic2();
template2.execute();
}

@Test
void templateMethodV2() {
AbstractTemplate template = new AbstractTemplate() {
@Override
protected void call() {
log.info("비즈니스 로직1 실행");
}
};
log.info("클래스 이름1={}", template.getClass());
template.execute();

AbstractTemplate template2 = new AbstractTemplate() {
@Override
protected void call() {
log.info("비즈니스 로직2 실행");
}
};
log.info("클래스 이름2={}", template2.getClass());
template2.execute();
}
}


 

 

참고로 intellij 롬복 플러그인 설치했고, build.gradle 에서 아래 코드도 추가되어 있는 상태입니다.

testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'

 

답변 1

2

안녕하세요. Jiwon님, 공식 서포터즈 David입니다.

클래스 상단에 @Slf4j 애노테이션이 빠진 것 같습니다. 추가하고 다시 시도해보시겠어요?

감사합니다.

Jiwon님의 프로필 이미지
Jiwon
질문자

덕분에 해결했습니다 빠른 답변 감사드립니다!

Jiwon님의 프로필 이미지
Jiwon

작성한 질문수

질문하기