提交 e21cfd15 authored 作者: 马晨俊's avatar 马晨俊

mcj:将主服务器ip抽成变量

上级 f2dbedd3
...@@ -11,6 +11,7 @@ import org.aspectj.lang.annotation.Before; ...@@ -11,6 +11,7 @@ import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -42,12 +43,15 @@ public class AopIntercept { ...@@ -42,12 +43,15 @@ public class AopIntercept {
public void doPointCut() { public void doPointCut() {
} }
@Value("${address}")
private String address;
@Around("doPointCut()") @Around("doPointCut()")
public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable { public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest(); HttpServletRequest request = attributes.getRequest();
String sessionId = request.getHeader("session"); String sessionId = request.getHeader("session");
String url = "http://120.55.57.35:12345/user/getLogin/"+sessionId; String url = "http://"+address+":12345/user/getLogin/"+sessionId;
ServerResponse serverResponse = restTemplate.getForObject(url, ServerResponse.class); ServerResponse serverResponse = restTemplate.getForObject(url, ServerResponse.class);
if(serverResponse!=null && serverResponse.getCode()!=200){ if(serverResponse!=null && serverResponse.getCode()!=200){
ResponseEntity.status(403).build(); ResponseEntity.status(403).build();
......
...@@ -65,4 +65,5 @@ spring.freemarker.template-loader-path=classpath:/templates ...@@ -65,4 +65,5 @@ spring.freemarker.template-loader-path=classpath:/templates
##Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3 ##Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3
#spring.redis.port=6379 #spring.redis.port=6379
##Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09 ##Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09
#spring.redis.password= #spring.redis.password=
\ No newline at end of file address=120.55.57.35
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论