|
@@ -2,6 +2,8 @@ package com.caimei365.cloud.config;
|
|
|
|
|
|
import com.caimei365.cloud.service.TouristService;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -11,6 +13,8 @@ import org.springframework.web.server.WebFilter;
|
|
|
import org.springframework.web.server.WebFilterChain;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -23,6 +27,16 @@ import java.util.Objects;
|
|
|
@Configuration
|
|
|
public class WebConfiguration implements WebFluxConfigurer {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TouristService touristService;
|
|
|
+
|
|
|
+ private static WebConfiguration webConfiguration;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ webConfiguration = this;
|
|
|
+ webConfiguration.touristService = this.touristService;
|
|
|
+ }
|
|
|
/**
|
|
|
* 获取客户端IP
|
|
|
* https://stackoverflow.com/questions/51192630/how-do-you-get-clients-ip-address-spring-webflux-websocket?rq=1
|
|
@@ -46,10 +60,10 @@ public class WebConfiguration implements WebFluxConfigurer {
|
|
|
ServerWebExchange mutatedServerWebExchange = exchange.mutate().request(mutatedServerHttpRequest).build();
|
|
|
chain.filter(mutatedServerWebExchange);
|
|
|
// 游客编号
|
|
|
- TouristService touristService = new TouristService();
|
|
|
- String touristId = touristService.touristInfo();
|
|
|
+ //TouristService touristService = new TouristService();
|
|
|
+ String touristId = webConfiguration.touristService.touristInfo();
|
|
|
return exchange.getSession().flatMap(session -> {
|
|
|
- session.getAttributes().put("touristId","touristId");
|
|
|
+ session.getAttributes().put("touristId", touristId);
|
|
|
return chain.filter(exchange);
|
|
|
});
|
|
|
}
|