From 3514488f2dba3cccc0c86f4c3891e37ce0167fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=ED=98=84=EC=9A=B0?= <83938394+yunuo46@users.noreply.github.com> Date: Sat, 11 May 2024 04:17:28 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20transaction=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../getaguitar/site/demo/Config/StompConfig.java | 12 +++++++----- .../site/demo/Controller/StompController.java | 3 --- .../site/demo/Interceptor/StompHandler.java | 2 ++ .../getaguitar/site/demo/Service/APIServiceImpl.java | 2 ++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/getaguitar/site/demo/Config/StompConfig.java b/src/main/java/getaguitar/site/demo/Config/StompConfig.java index 5eb9ef8..e25c6d4 100644 --- a/src/main/java/getaguitar/site/demo/Config/StompConfig.java +++ b/src/main/java/getaguitar/site/demo/Config/StompConfig.java @@ -1,7 +1,9 @@ package getaguitar.site.demo.Config; +import getaguitar.site.demo.Interceptor.StompHandler; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.simp.config.ChannelRegistration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.StompEndpointRegistry; @@ -12,7 +14,7 @@ @RequiredArgsConstructor public class StompConfig implements WebSocketMessageBrokerConfigurer { - //final StompHandler stompHandler; + final StompHandler stompHandler; @Override public void registerStompEndpoints(StompEndpointRegistry registry) { @@ -24,8 +26,8 @@ public void configureMessageBroker(MessageBrokerRegistry registry) { registry.setApplicationDestinationPrefixes("/app"); } -// @Override -// public void configureClientInboundChannel(ChannelRegistration registration) { -// registration.interceptors(stompHandler); -// } + @Override + public void configureClientInboundChannel(ChannelRegistration registration) { + registration.interceptors(stompHandler); + } } \ No newline at end of file diff --git a/src/main/java/getaguitar/site/demo/Controller/StompController.java b/src/main/java/getaguitar/site/demo/Controller/StompController.java index d0587b6..cbee59a 100644 --- a/src/main/java/getaguitar/site/demo/Controller/StompController.java +++ b/src/main/java/getaguitar/site/demo/Controller/StompController.java @@ -4,15 +4,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.event.EventListener; -import org.springframework.messaging.handler.annotation.MessageMapping; -import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.simp.SimpMessageSendingOperations; import org.springframework.messaging.simp.stomp.StompHeaderAccessor; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.socket.messaging.SessionConnectEvent; import org.springframework.web.socket.messaging.SessionDisconnectEvent; -import java.util.Map; @RestController diff --git a/src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java b/src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java index c933f6c..d5d9978 100644 --- a/src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java +++ b/src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java @@ -28,6 +28,8 @@ public void postSend(Message message, MessageChannel channel, boolean sent) { case DISCONNECT: LOGGER.info("sessionId Disconnected {}", sessionId); break; + case null: + break; default: break; } diff --git a/src/main/java/getaguitar/site/demo/Service/APIServiceImpl.java b/src/main/java/getaguitar/site/demo/Service/APIServiceImpl.java index f9aa5e8..45ad60d 100644 --- a/src/main/java/getaguitar/site/demo/Service/APIServiceImpl.java +++ b/src/main/java/getaguitar/site/demo/Service/APIServiceImpl.java @@ -2,6 +2,7 @@ import getaguitar.site.demo.Dto.ResUserDto; import getaguitar.site.demo.Entity.UserEntity; import getaguitar.site.demo.Repository.UserRepository; +import jakarta.transaction.Transactional; import org.springframework.stereotype.Service; import org.apache.commons.lang3.RandomStringUtils; @@ -13,6 +14,7 @@ public APIServiceImpl(UserRepository userRepository) { } @Override + @Transactional public ResUserDto getUser(){ String username = RandomStringUtils.randomAlphanumeric(5); int id = userRepository.save(UserEntity.builder()