
error: Cannot resolve symbol 'WebSecurityConfigurerAdapter'
error: 'csrf()' is deprecated since version 6.1
error: 'and()' is deprecated since version 6.1
원인
Spring Security 6.1 버전에서 WebSecurityConfigurerAdapter가 deprecated되고 새로운 보안 설정 방식이 도입되었다.
해결 방법
SecurityFilterChain을 사용하는 새로운 방식으로 보안 설정을 변경했다.
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) {
return http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
.requestMatchers("/", "/member/register").permitAll()
.requestMatchers("/admin/**").hasAuthority("ROLE_ADMIN")
.anyRequest().authenticated()
)
.formLogin(form -> form
.loginPage("/member/login")
.failureHandler(getFailureHandler())
.permitAll()
)
.build();
}
}
error: Cannot resolve symbol 'FastlmsApplication'
원인
ServletInitializer 클래스에서 잘못된 메인 애플리케이션 클래스를 참조하고 있었다.
해결 방법
올바른 메인 애플리케이션 클래스로 참조를 수정했다.
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ZbOnlineCourseProjectApplication.class);
}
}
error: Could not autowire. No beans of 'MailComponents' type found
원인
MailComponents 클래스가 Spring Bean으로 등록되지 않았고, 필요한 설정이 누락되었다.
해결 방법
@Component
public class MailComponents {
@Autowired
private JavaMailSender javaMailSender;
}
spring:
mail:
host: smtp.gmail.com
port: 587
username: ${MAIL_USERNAME}
password: ${MAIL_PASSWORD}
properties:
mail:
smtp:
auth: true
starttls:
enable: true
error: The declared package does not match the expected package
원인
테스트 클래스의 패키지 선언이 실제 디렉토리 구조와 일치하지 않았다.
해결 방법
올바른 패키지 경로로 수정했다.
package com.zerobase.zbonlinecourseproject.components;
@SpringBootTest
@TestPropertySource(locations = "classpath:application.yml")
class MailComponentsTest {
// ...
}
보안 설정 개선
메일 서비스 통합
테스트 코드 개선
Spring Boot 프로젝트에서 발생한 여러 오류들을 해결하면서, 프레임워크의 버전 변화에 따른 대응 방법과 의존성 주입의 중요성을 깊이 이해할 수 있었다. 특히 Spring Security의 새로운 방식은 더 직관적이고 타입 안전한 설정을 가능하게 했다. 앞으로도 이러한 경험을 바탕으로 더 견고한 애플리케이션을 만들어 나가야겠다.
"문제는 답을 찾는 것이 아니라,
문제를 해결하는 과정에서 배우는 것이다."
-앨버트 아인슈타인-
안녕하세요! 개발자 준비하시는 분이나 현업에 종사하고 계신 분들만 할 수 있는 시급 25달러~51달러 LLM 평가 부업 공유합니다~ 제 블로그에 자세하게 써놓았으니 관심있으시면 한 번 읽어봐주세요 :)