首页 » Latest Post

java 查看版本的命令大家再熟悉不过了

java -version

但是java 11的写法是这样的

java --version

其实java 11 的才是比较标准的linux命令,linux中,一个杠代表短命令,比如-v,两个杠表示全拼命令 --version,这个困扰圈圈很久的问题,居然意外发现改了,算是一个小惊喜

请直接参考这个链接文章 http://greenhtml.com/archives/eureka-zhilian.html

1 服务端code 请直接参考这个链接文章 http://greenhtml.com/archives/eureka-zhilian.html

@RequestMapping("/user/InfoByCode")
        @ResponseBody
        @ApiOperation(value = "gateway 获取用户ID,用于放到header里面", httpMethod = "POST")
        public UserInfoView InfoByCode(@RequestParam("code") String code) {
            return UserInfoView.of(users.findFirstByInvitationCode(code));
        }

2 客户端调用直接指定url 请直接参考这个链接文章 http://greenhtml.com/archives/eureka-zhilian.html

@FeignClient(value = "THORUSER",url = "http://localhost:3331")
public interface UserClient {
  @RequestMapping("/user/InfoByCode")
   UserInfoView InfoByCode(@RequestParam("code") String code);

}

3 这样就不经过eureka,直连微服务了。 请直接参考这个链接文章 http://greenhtml.com/archives/eureka-zhilian.html

注意点:不要再返回 chain.filter...,直接return response.setComplete,这样就返回401 了,否则就会继续网后面执行,可能会返回200了。笔者就犯了这个错误

 
  @Component
    public class Session2header extends AbstractNameValueGatewayFilterFactory {
    
        private static final Logger log = LoggerFactory.getLogger(GatewayFilterFactory.class);
    
    
    
        @Override
        public GatewayFilter apply(NameValueConfig config) {
            return (exchange, chain) -> {
    
        //get UID
        ...
                if (!isSucess) {
                    ServerHttpResponse response = exchange.getResponse();
                    response.setStatusCode(HttpStatus.UNAUTHORIZED);
                    return response.setComplete();
    //                return chain.filter(exchange.mutate().response(response).build());
                }

                ServerHttpRequest request = exchange.getRequest().mutate()
                        .header("user_id", uid)
                        .build();
                return chain.filter(exchange.mutate().request(request).build());
            };
        }
    
        private String getUidFromRedis(String token) {
            return userClient.IdByToken(token);
        }
    }

  Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:950) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    ... 6 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_121]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_121]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:942) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    ... 8 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    ... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@3a147ae1]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4907) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5042) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    ... 6 common frames omitted
Caused by: java.lang.IllegalArgumentException: The main resource set specified [/tmp/tomcat-docbase.6227775345915450173.2222] is not valid
    at org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:748) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:706) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]

最后发现是磁盘满了,
使用下面的命令查看磁盘使用情况

df -h

发现/dev/vda1 磁盘占用100%,然后查看/tmp日志的情况

 du -sh /tmp

发现spring cloud gateway 占用了大量的日志文件
删掉后,发现并没有减少,使用命令

 lsof | grep delete

发现这些删除,但是被程序占用了的文件,只有新启动gateway 程序,日志文件才被删除,解决。