Ver Fonte

增加socket开关

gogs há 1 mês atrás
pai
commit
0e31502ca5

+ 8 - 5
game-business/src/main/java/com/game/business/websocket/WebSocketConnent.java

@@ -5,8 +5,13 @@ import com.game.business.config.GameTwoConfig;
 import com.game.business.config.SpringContextSetting;
 import com.game.business.util.Common;
 import com.game.business.websocket.client.*;
+import com.game.common.utils.spring.SpringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Configurable;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
 
 import javax.websocket.ContainerProvider;
 import java.net.URI;
@@ -20,10 +25,7 @@ public class WebSocketConnent {
     private int WS_CONNENT_NUM = 0;
     private int WS_CONNENT_MAX_NUM = 10;
 
-    @Value("${websocket.switch}")
-    private boolean socketSwitch;
-
-
+    public WebSocketConnent(){}
 
     public WebSocketConnent(String WS_URL, String WS_REMARK_URL, String WS_URL_NAME){
         this.WS_URL = WS_URL;
@@ -32,7 +34,8 @@ public class WebSocketConnent {
     }
 
     public void connect() throws Exception{
-        while (socketSwitch){
+        Environment environment = SpringUtils.getBean(Environment.class);
+        while (environment.getProperty("websocket.switch",boolean.class)){
             try {
                 System.out.println("正在" + (this.WS_CONNENT_NUM == 0 ? "" : ("第" + this.WS_CONNENT_NUM + "次")) + "连接WebSocket[" + this.WS_URL_NAME + "]......");