微服务遇到的问题

776 阅读3分钟

版本冲突导致的,提示需要更新

Caused by: java.lang.ClassNotFoundException:
com.netflix.config.DeploymentContext$ContextKey

<dependency>
    <groupId>com.netflix.archaius</groupId>
    <artifactId>archaius-core</artifactId>
    <version>0.7.7</version>
</dependency>

Nacos找不到服务名称,因为版本使用的比较新,不会自动引入bootstrap.yml文件

Param ‘serviceName‘ is illegal, serviceName is blank

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

因为spring的版本太低了,JDK的版本太高了

Failed to read candidate component class: file [ ]; nested exception is org


多个参数需要加 @PathVariable 指定参数名称,如果加了还报错,需要加入指定的value值

Error creating bean with name 'clients.StorageClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract java.lang.Integer clients.StorageClient.updateCount(java.lang.String,java.lang.Integer)

@GetMapping("/group/selectCreateTime/{id}")
Date getCreateDate(@PathVariable(value = "id") String id);

因为spring4.0之后对参数的校验比较严格,需要给Feign客户端方法参数加@RequestParam

FactoryBean threw exception on object creation nested exception is java.lang.IllegalStateException


狂刷spring日志信息,是因为配置进行统一管理 nacos 依赖导致,需要创建bootstrap.yml

========CONDITIONS EVALUATION REPORT
Positive matches: -----------------

在bootstrap中添加才生效

logging:
  level:
    org:
      springframework:
        boot:
          autoconfigure: ERROR

服务在nacos中不表明分组名无法注册到seata服务中,原因需要修改这个seata-tc-server

can not get cluster name in registry config 'service.vgroupMapping.seata-demo', please make sure registry config correct

while it seems to fit format ‘yyyy-MM-dd‘T‘HH:mm:ss.SSSZ‘, parsing fails (leniency? null))

前端提交字符串到后台映射为Date类型,可以加上@DateTimeFormat,只是适合springMvc项目,springgboot项目需要以下解决

spring: 
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss

Field remoteLogService in com.ruoyi.common.log.service.AsyncLogService required a bean of type 'com.ruoyi.system.api.RemoteLogService' that could not be found.

原因:若依框架已经加入了Enable注解,无需再次加入

mybatis 中使用foreach中使用if标签就报这个错误,我后期再测试一下,目前去掉就好了

Available parameters are [arg1, arg0, param1, param2]

feign传对象,接收到空对象问题

原因是因为没有加requestBody问题,传对象会被当做post传递,所以要改成postMapping

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main. allow-circular-references to true.

原因是依赖循环引用是不鼓励的,默认情况下是禁止的。更新应用程序以删除bean之间的依赖循环。作为最后的手段,可以通过设置spring.main来自动打破循环。allow-circular-references为true。

spring:
  main:
    allow-circular-references: true

Validation failed for object='product'. Error count: 1

表示这个实体类的处理方式对应不上,或者是与数据库的字段类型对不上,我这里是因为前端传递的是string类型时间字符串,我后台没有设置,DateFormat

invalid comparison: java.util.Date and java.lang.String

这个问题表示,日期类型在进行转字符串的时候报错了,加上dateformat和jsonformat都没有效果,因为是sql里面判断的时候无需判断是不是空,下面正确使用

<if test="time != null">
    and tco.create_date > #{time}
</if>

Tomcat 打war包乱码

在tomcat 中 config 和 logging.properties

java.util.logging.ConsoleHandler.encoding = GBK

pagehelp 和 mybatisPlus 冲突

mybatisplus-springboot-starter

<exclusions>
    <exclusion>
        <artifactId>jsqlparser</artifactId>
        <groupId>com.github.jsqlparser</groupId>
    </exclusion>
    <exclusion>
        <artifactId>mybatis</artifactId>
        <groupId>org.mybatis</groupId>
    </exclusion>
</exclusions>

提高版本号

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.4.6</version>
</dependency>

事物导致,查询数据不返回结果,但是返回获得的行

原因未知,但是加上事物即可

JSON.tostring 返回为空

是因为对象中缺少get方法

mybatisplus 执行报错

Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment[java.lang.ExceptionInInitializerError]

升级到最新版本, 3.5.3.1