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