# kw-microservices **Repository Path**: kkmy/kw-microservices ## Basic Information - **Project Name**: kw-microservices - **Description**: 模仿若依开源框架,搭建自己的微服务平台 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2023-05-16 - **Last Updated**: 2025-11-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # kw-microservices 模仿若依开源框架,搭建自己的微服务平台 ## 环境准备 ### 分布式文件存储MinIO #### 上传下载原理 #### 前端文件上传-秒传 https://blog.csdn.net/qq_43437874/article/details/123393489 ### 前端应用 #### 认证授权中心 127.0.0.1 auth.kwzone.cloud #### 第三方应用 127.0.0.1 kwsphere.cloud ## 问题记录 ### 前端 #### sockjs-node/info 前端一直有这个请求 #### cookie设置问题 前端的异步请求,为什么会把后端的sessionId返回给前端呢 #### 前端安全 http only HttpOnly是包含在Set-Cookie HTTP响应头文件中的附加标志。 生成cookie时使用HttpOnly标志有助于降低客户端脚本访问受保护cookie的风险(如果浏览器支持)。 这个意思就是说,如果某一个Cookie 选项被设置成 HttpOnly = true 的话,那此Cookie 只能通过服务器端修改,Js 是操作不了的 #### session续期原理 #### 前端应用请求/oauth/token,没有携带客户端headers,前端报错跨域请求 #### 路由hash模式,授权重定向后,后续的路径会携带授权码,刷新会报错 ### 后端 #### windows启动jar报错 org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1 解决办法 启动参数增加-Dfile.encoding=utf-8 java -jar -Dloader.path="./lib" -Dfile.encoding=utf-8 kw-gateway-1.0.0.jar #### 配置nacos config报错 ```text ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - 'File' option has the same value "C:\Users\pc\logs/nacos/config.log" as that given for appender [CONFIG_LOG_FILE] defined earlier. ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting. ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - For more information, please visit http://logback.qos.ch/codes.html#earlier_fa_collision ``` 解决,升级nacos-client依赖 ```xml org.springframework.cloud spring-cloud-starter-gateway com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.nacos nacos-client com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config com.alibaba.nacos nacos-client com.alibaba.nacos nacos-client 2.2.1 compile ``` #### 邮件配置465报错 javax.mail.MessagingException: Got bad greeting from SMTP host: smtp.qq.com, port: 465, response: [EOF] 解决:开启ssl ```yaml spring: mail: host: smtp.qq.com username: "" password: "" port: 465 properties: mail: smtp: ssl: enable: true ``` #### SpringBootAdmin监控Auth服务 只启动了一个实例,但是检测到两个实例 应该是springboot admin 整合了nacos auth服务又整合springbootadmin client导致 所以微服务就不需要配置admin client了 #### feign调用oauth服务,username参数传的是NONE_PROVIDED 上游服务传参,忘记加@RequestBody注解了,导致值为null #### feign调用header信息,没有传 FeignAuthApiConfiguration类需要加@Configuration注解 但实际项目中没有加注解,难道是版本问题? #### PathVariable annotation was empty on param 0. java.lang.IllegalStateException: PathVariable annotation was empty on param 0. 解决:指定value @PathVariable(value = "userNo") #### aop配置,计算方法的执行时间 todo #### 整合rabbitmq 交换机、队列应该如何合理创建, 生产者创建、消费者创建,还是控制台创建 #### 整合redis报错 The URL 'localhost' is not valid for configuring Spring Data Redis. The scheme 'null' is not supported. Action: Use the scheme 'redis://` for insecure or `rediss://` for secure Redis standalone configuration. 修改配置为 redis: url: redis://123456@localhost:6379 org.springframework.boot.autoconfigure.data.redis.RedisUrlSyntaxException: Invalid Redis URL 'localhost' #### spring.mvc.throw-exception-if-no-handler-found: true 配置这个,导致swagger无法访问,不配置这个无法捕获404资源异常 spring.resources.add-mappings: false #### 整合swagger 如果方法使用的是@RequestMapping这个注解 在swagger中会显示多个请求方式的controller方法 #### 无法访问javax.servlet.ServletException 打包报错 解决,引入依赖 ```xml javax.servlet javax.servlet-api ``` #### feign请求,响应超时,本地负载均衡无法找到指定服务 yml中,没有配置相关参数 #### 日志配置,启动异常 in ch.qos.logback.core.pattern.parser.Compiler@79476a4e - [tid] is not a valid conversion word 解决: [%X{tid}] -> [%X{tid}] #### ribbon请求报错 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ribbonClientConfiguration': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.netflix.client.config.CommonClientConfigKey 引入如下依赖解 ```xml com.google.guava guava 18.0 ``` 貌似还是依赖兼容问题,当前cloud alibaba版本是2.2.9.RELEASE,nacos2.1.1 #### openfeign请求报错InvalidDefinitionException 下游服务,接口实体没有序列化 com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class pers.kw.file.dto.FileDto and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: pers.kw.protocol.R["body"]) 需要自定义HttpMessageConverter configureMessageConverters 允许实体没有属性 #### com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `pers.kw.protocol.R` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator) 实体需要加无参构造方法 #### com.netflix.client.ClientException: Load balancer does not have available server for client: file-service @EnableDiscoveryClient #### 浏览器请求中文乱码问题 converters.add(new StringHttpMessageConverter( StandardCharsets.UTF_8)); configureMessageConverters List fastMediaTypes = new ArrayList<>(); fastMediaTypes.add( MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); #### 授权 授权接口,如果异步请求如何获取授权码 http://localhost:9090/oauth/authorize?client_id=kwsphere&response_type=code #### 自定义spring security oauth2三个页面 https://baijiahao.baidu.com/s?id=1736936966974655693&wfr=spider&for=pc ##### 登录页面 ##### 授权页面 ##### 授权异常页面 ## 部署 ## Windows单机 ## Docker集群 # org.apache.commons.io使用总结 IOUtils FileUtils