Merge branch 'be/mail' into 'backend'

feat: mail 이메일 인증 비동기 처리 추가

See merge request s11-webmobile1-sub2/S11P12A701!136
This commit is contained in:
박정민 2024-08-09 13:50:02 +09:00
commit f10e80003f
3 changed files with 36 additions and 0 deletions

View File

@ -3,7 +3,9 @@ package com.edufocus.edufocus;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
@EnableAsync
@EnableJpaAuditing
@SpringBootApplication
public class EdufocusApplication {

View File

@ -0,0 +1,32 @@
package com.edufocus.edufocus.global.config;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import java.util.concurrent.Executor;
@Configuration
@EnableWebMvc
public class AsyncConfig implements AsyncConfigurer {
@Override
@Bean(name = "mailExecutor")
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("MailExecutor-");
executor.initialize();
return executor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return AsyncConfigurer.super.getAsyncUncaughtExceptionHandler();
}
}

View File

@ -8,6 +8,7 @@ import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Random;
@ -27,6 +28,7 @@ public class MailServiceImpl implements MailService {
private final RedisUtil redisUtil;
@Override
@Async("mailExecutor")
public void sendMail(String email) {
String code = createRandomCode();