[Spring Boot] 회원가입 구현 중 발생한 오류 해결 (Security, Bean 주입, 메일인증)

D3F D3V J30N·2025년 1월 8일
1

Error

목록 보기
2/4
post-thumbnail

1. 첫 번째 오류: Spring Security Configuration

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();
    }
}

2. 두 번째 오류: ServletInitializer 클래스 참조

error: Cannot resolve symbol 'FastlmsApplication'
  • 원인
    ServletInitializer 클래스에서 잘못된 메인 애플리케이션 클래스를 참조하고 있었다.

  • 해결 방법
    올바른 메인 애플리케이션 클래스로 참조를 수정했다.

public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ZbOnlineCourseProjectApplication.class);
    }
}

3. 세 번째 오류: Bean 주입 실패

error: Could not autowire. No beans of 'MailComponents' type found
  • 원인
    MailComponents 클래스가 Spring Bean으로 등록되지 않았고, 필요한 설정이 누락되었다.

  • 해결 방법

    • Component 어노테이션 추가
    • 메일 설정 추가
    • 의존성 추가
@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

4. 네 번째 오류: 패키지 선언 불일치

error: The declared package does not match the expected package
  • 원인
    테스트 클래스의 패키지 선언이 실제 디렉토리 구조와 일치하지 않았다.

  • 해결 방법
    올바른 패키지 경로로 수정했다.

package com.zerobase.zbonlinecourseproject.components;

@SpringBootTest
@TestPropertySource(locations = "classpath:application.yml")
class MailComponentsTest {
    // ...
}

프로젝트 개선사항

  1. 보안 설정 개선

    • Spring Security 6.1 최신 방식 적용
    • Lambda DSL을 활용한 가독성 있는 보안 설정
  2. 메일 서비스 통합

    • Gmail SMTP 서버 연동
    • 회원가입 인증 메일 발송 기능 구현
    • 환경 변수를 통한 보안 강화
  3. 테스트 코드 개선

    • 회원가입 프로세스 테스트 구현
    • 메일 발송 기능 테스트 추가
    • 실제 데이터베이스 연동 테스트

인사이트

Spring Boot 프로젝트에서 발생한 여러 오류들을 해결하면서, 프레임워크의 버전 변화에 따른 대응 방법과 의존성 주입의 중요성을 깊이 이해할 수 있었다. 특히 Spring Security의 새로운 방식은 더 직관적이고 타입 안전한 설정을 가능하게 했다. 앞으로도 이러한 경험을 바탕으로 더 견고한 애플리케이션을 만들어 나가야겠다.

오늘의 명언

"문제는 답을 찾는 것이 아니라,
문제를 해결하는 과정에서 배우는 것이다."

-앨버트 아인슈타인-

profile
Problem Solver

1개의 댓글

comment-user-thumbnail
2025년 1월 8일

안녕하세요! 개발자 준비하시는 분이나 현업에 종사하고 계신 분들만 할 수 있는 시급 25달러~51달러 LLM 평가 부업 공유합니다~ 제 블로그에 자세하게 써놓았으니 관심있으시면 한 번 읽어봐주세요 :)

답글 달기