diff options
author | Vitaly Takmazov | 2017-10-16 00:57:29 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-10-16 00:57:29 +0300 |
commit | 52d1d04cc129d6df7b54bd41e882e353add0e4ce (patch) | |
tree | 443b213932fcdc2baded275eb9877b188641740f | |
parent | 4687e8130f722b05239fa9570f73c60aa4f16bc7 (diff) |
web: move scheduler config to base web config
-rw-r--r-- | juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java | 15 | ||||
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java | 21 |
2 files changed, 19 insertions, 17 deletions
diff --git a/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java b/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java index efbe66cb..abf8482c 100644 --- a/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java +++ b/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java @@ -29,19 +29,23 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; /** * Created by vitalyster on 28.06.2016. */ @Import(DataConfiguration.class) @Configuration -public class BaseWebConfiguration implements WebMvcConfigurer { +public class BaseWebConfiguration implements WebMvcConfigurer, SchedulingConfigurer { @Override @@ -76,4 +80,13 @@ public class BaseWebConfiguration implements WebMvcConfigurer { public ImagesService imagesService() { return new ImagesServiceImpl(); } + @Override + public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + taskRegistrar.setScheduler(taskExecutor()); + } + + @Bean(destroyMethod="shutdown") + public Executor taskExecutor() { + return Executors.newScheduledThreadPool(100); + } } diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java index 8e2659a3..d1a6296a 100644 --- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java +++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java @@ -20,19 +20,17 @@ package com.juick.ws.configuration; import com.juick.server.configuration.BaseWebConfiguration; import com.juick.server.protocol.JuickProtocol; import com.juick.ws.WebsocketComponent; -import org.springframework.context.annotation.*; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.SchedulingConfigurer; -import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.web.socket.config.annotation.EnableWebSocket; import org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistry; import org.springframework.web.socket.config.annotation.WebSocketConfigurer; import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - /** * Created by aalexeev on 11/24/16. */ @@ -41,7 +39,7 @@ import java.util.concurrent.Executors; @EnableScheduling @EnableWebSocket @PropertySource("classpath:juick.conf") -class WebsocketConfiguration extends BaseWebConfiguration implements WebSocketConfigurer, SchedulingConfigurer { +class WebsocketConfiguration extends BaseWebConfiguration implements WebSocketConfigurer { @Bean public WebsocketComponent wsHandler() { @@ -66,13 +64,4 @@ class WebsocketConfiguration extends BaseWebConfiguration implements WebSocketCo container.setMaxBinaryMessageBufferSize(8192); return container; } - @Override - public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { - taskRegistrar.setScheduler(taskExecutor()); - } - - @Bean(destroyMethod="shutdown") - public Executor taskExecutor() { - return Executors.newScheduledThreadPool(100); - } } |