各种出错以及解决方法(持续更新)

后端

Java开发

Spring

java: 找不到符号 方法 allowedOriginPatterns

原因和解决方法1

我这是修改 SpringBoot版本后出现的问题。

// 改成这样就行
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
            .allowedOrigins("*")
            // 之前是 .allowedOriginPatterns("*")
            .allowCredentials(true)
            .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
            .maxAge(3600);
    }
}

循环依赖

三个 service 出现循环依赖,构建 A 需要 B,构建 B 需要 C,构建 C 需要 A。

原因和解决方法1

springboot2.6 开始,默认禁止循环依赖,所以我们需要允许循环依赖。

spring:
  main:
    allow-circular-references: true

gitlab删除项目

Settings->General->Advanced->Expend -> delete project。

idea

idea项目后有 []

这是因为项目的名称和 pom.xml文件中的名称不一致。

项目没有 maven依赖,配置文件也不是绿叶

原因和解决方法1

这个应该是因为项目是直接复制粘贴的。

最好是放到 git 上,然后从 git 拉项目,而不是自己复制粘贴。

如果项目没什么问题但是无法启动

原因和解决方法1

我遇到的报错是这个:Failed to read candidate component class: file [D:

就把项目的 maven 进行 clean、compile 就行了。

git管理-.gitignore文件

HELP.md
pinlor-service-base/target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
**/target/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
​
**/mvnw
**/mvnw.cmd
**/.mvn
**/target/

gitignore文件不生效

解决idea的.gitignore有时不起作用的问题_idea中配置忽略文件其中部分不起作用-CSDN博客

依赖版本存在却爆红

原因和解决方案1

有可能是因为你是依赖管理的项目,那么有些依赖只要子项目不引用,父项目就不会去下载这个依赖,所以会爆红。

所以解决方法也很简单,你要是看得不爽就让子类引用一下这个依赖,然后刷一下 maven,就能下下来;不管也没事,用到了再下也是一样的。

services 启动项目不显示端口号

原因和解决方法1

关闭项目重启 idea 再启动项目可能就行了。

原因和解决方法2

IDEA工具篇——Service窗口服务开启不显示端口号问题_idea services窗口不显示端口号-CSDN博客

zookeeper

启动闪退

在 zkServer.cmd 最后第二行加上 pause,然后再启动就能看到报错信息了。

mybatis

Parameter 'shopNoList' not found.

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'shopNoList' not found. Available parameters are [list]
原因和解决方法1

可能是因为没有给 mapper.java 的方法的参数指定 @Param,

List<ShopInfo> getShopWithoutShopNoList(@Param("shopNoList") List<String> shopNoList);

Invalid bound statement (not found)

报错的是:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pinlor.servicecommon.user.mapper.UserMapper.findUserInfoByUsername;

就是说 mapper.java 找不到他的 mapper.xml。

原因和解决方法1

我这次是因为打包打不进去,去看看 target 里面,是不是把 mapper.xml 也打包进去了,如果没有打包进去,那就可以使用这个方法。如果是其他的,很有可能是做的指定映射不对。

就往 pom.xml 中加入这个插件,让 maven 打包的时候把 .xml 和 .properties 也打包进去。

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.json</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>
</build>

主键无法回显问题

原因和解决方法1

有可能是主键回显了,但是 dubbo 用的不是我们传的那个对象。因为 dubbo 是复制了一份然后去使用的,那么这个实体和那个就是两个地址的,所以没有主键。

这个是主键回显逻辑。

useGeneratedKeys="true" keyProperty="classId">

两个解决方法:方法返回主键然后手动赋值 或者 public class ABC extends BaseEntity

mysql栈溢出

Error querying database. Cause: java.sql.SQLException: Thread stack overrun: 230296 bytes used of a 262144 byte stack, and 32000 bytes needed. Use 'mysqld --thread_stack=#' to specify a bigger stack.

意思就是太小了,所以出错,

解决方法1

扩大内存,JVM调优,调大栈内存,

jvm大小_SpringBoot 深度调优_-xx:metaspacesize默认值-CSDN博客

MySQL thread_stack连接线程的优化_Mysql_脚本之家

解决方法2

因为数据太大了,那就分批进行,使用 guava。

List<User> users = userService.findAll();
//按每50个一组分割
List<List<User>> parts = Lists.partition(users, 50);
parts.stream().forEach(list -> {
            process(list);
});
​
List<Map<String,Object>> list3 = list1.stream().parallel().filter(a -> list2.stream()
                          .anyMatch(b-> Objects.equals(a.get("age"), b.get("age"))))
    .collect(Collectors.toList());
    

使用 saveOrUpdateBatch 时出现 id 不存在错误

原因和解决方法1

tableInfo.getKeyProperty() 获取到了主键的名称,然后 idVal 就是想获取指定对象的主键的值,但是 Mybatis-Plus 的 ReflectionKit.getFieldValue(entity, keyProperty) 有问题,只能获取到 Class 这个类,所以 Map 是空的,也获取不到主键的值。使用 ReflectionKit.getFieldMap 可以自行获取。

// Mybatis-Plus 3.5.2 有这个问题,之后可能被修复了。
public static Object getFieldValue(Object entity, String fieldName) {
  // entity 是 Object类型,所以 entity.getClass() 只能获取到 java.lang.Class
  Class<?> cls = entity.getClass();
  // 这个 Map 一定是空的,
  Map fieldMaps = getFieldMap(cls);
  try {
    Field field = (Field)fieldMaps.get(fieldName);
    Assert.notNull(field, "Error: NoSuchField in %s for %s.  Cause:", new Object[]{cls.getSimpleName(), fieldName});
    field.setAccessible(true);
    return field.get(entity);
  } catch (ReflectiveOperationException var5) {
    throw ExceptionUtils.mpe("Error: Cannot read field in %s.  Cause:", var5, new Object[]{cls.getSimpleName()});
  }
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveOrUpdateBatch(Collection<T> entityList) {
    TableInfo tableInfo = TableInfoHelper.getTableInfo(this.currentModelClass());
    Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");
    String keyProperty = tableInfo.getKeyProperty();
    Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");
    return executeBatch(entityList, BATCH_SIZE, (sqlSession, entity) -> {
        Object idVal = this.getMethodValue(this.currentModelClass(), entity, keyProperty);
        if (StringUtils.checkValNull(idVal) || Objects.isNull(selectById((Serializable) idVal))) {
            sqlSession.insert(tableInfo.getSqlStatement(SqlMethod.INSERT_ONE.getMethod()), entity);
        } else {
            MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
            param.put(Constants.ENTITY, entity);
            sqlSession.update(tableInfo.getSqlStatement(SqlMethod.UPDATE_BY_ID.getMethod()), param);
        }
    });
}
​
// 使用 ReflectionKit.getFieldMap 可以自行获取。
private Object getMethodValue(Class<?> cls, Object entity, String fieldName) {
    Map<String, Field> fieldMaps = ReflectionKit.getFieldMap(cls);
    try {
        Field field = fieldMaps.get(fieldName);
        Assert.notNull(field, "Error: NoSuchField in %s for %s.  Cause:", cls.getSimpleName(), fieldName);
        field.setAccessible(true);
        return field.get(entity);
    } catch (ReflectiveOperationException e) {
        throw ExceptionUtils.mpe("Error: Cannot read field in %s.  Cause:", e, cls.getSimpleName());
    }
}

lombok

在 set 处提示:找不到符号

五种方式助你排查Idea使用Lombok 编译报“找不到符号“的问题_lombok 找不到符号-CSDN博客

原因和解决方法1

我是通过加入插件解决的。

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <annotationProcessorPaths>
          <path>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
          </path>
        </annotationProcessorPaths>
      </configuration>
    </plugin>
  </plugins>
</build>

nacos

加上 : 就是给默认值,防止报错的。

@Value("${test.array1:}")

拿不到 nacos 的 list

https://www.cnblogs.com/javastack/p/13862164.html

list 无法通过 @Value 拿到,拿 list 或 map 只能用对象的方式。

#内部接口配置
internal: 
  exclude-shop-no-list: 
    - 30014
    - 30016
​
​
​
// 使用对象接收的话
@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "internal")
public class TrialProperties {
  private List<Integer> exclude-shop-no-list;
}
​
​
​
#钉钉配置
dingding: 
  msg: 
    shop-no-config: 
      10002: 
        - 200220826001 
        - 200220826002 
        - 200220826003 
        - 12321 
      10019: 
        - 121343
        
@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "dingding.msg")
public class DingDingMsgProperties {
    /**
     * 特殊商城中的商品推送钉钉消息
     */
    private Map<String, List<String>> shopNoConfig;
}
数组可以直接拿到
test:
  array1: aaa,bbb,ccc
  array2: 111,222,333
  array3: 11.1,22.2,33.3
​
@Value("${test.array1}")
private String[] testArray1;
@Value("${test.array2}")
private int[] testArray2;
@Value("${test.array3}")
private double[] testArray3;

nacos启动闪退

再 startup.cmd 最后加上 pause,就能不闪退,看到报错信息。

前端调后端的请求超时

nginx 出现504 Gateway Time-out的解决方法_nginx 504 gateway time-out-CSDN博客

数组与集合

asList 后的数组无法 add、remove

Arrays.asList 会 new 一个 ArrayList,但是生成的 List 是 Arrays 这个类的内部类 ArrayList,就是说这个是他自己写的 ArrayList,得到的是一个 size 固定的定长集合,只能看,不能编辑。

并且继承了 AbstractList 但是没有实现 add方法,所以不能编辑,AbstractList 的 add 一被调用就会报错。

JSON对象与字符串

JSONObject 的 getString net.sf.json.JSONException

org.json.JSONObject 的 getString方法如果取不到对应的 key 会抛出异常,optString方法则不会。

Navicat

2003 就是说 MySQL服务未启动

原因和解决方法1

应该就是服务没启动,管理员启动 cmd。

d:
cd D:\MySoftware\MySQL\mysql-8.0.32-winx64\bin
net start mysql

ORA-28547: connection to server failed

ORA-28547: connection to server failed, probable Oracle Net admin error。

原因和解决方法1

可能是环境的 oci文件不对,工具->选项->环境,修改 oci环境的文件。

注意昂,oracle 和 oci 和 mysql 的 oci 不可互通,就是说你连什么数据库你得切换这个环境文件。

Instant Client for Microsoft Windows (x64) 64-bit | Oracle 中国

MySQL

Failed to configure a DataSource

全部是:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured。

原因和解决方法1

反正就是 <resources> 那块全删了,然后子项目把 <packaging>pom 这行给删掉,不然就一直连不上数据库。

原因和解决方法2

如果你既引入了数据库相关依赖,又引入了 druid 的依赖,druid 会导致再次扫描数据源,所以要 exclude 两个。

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})

时间缺少 8小时

就是时区不对,不是东八区。mysql8时区设置_解决MySQL8.0时区的问题步骤-CSDN博客

解决方法1

在配置文件 my.cnf 中加入此配置。

default-time-zone='Asia/Shanghai'

maven

spring.profiles.active 不生效

原因和解决方法1

说明没配置好,参数的值是可以自定义的,主要是在项目或父项目中加入插件和资源。

<profiles>
  <!--开发-->
  <profile>
    <id>dev</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
      # 这个名字是自定义统一的
      <profiles.active>dev</profiles.active>
      <!--<repository.id>dev</repository.id>
      <repository.name>dev Repository</repository.name>
      <repository.url>https://nexus.pharmakeyring.com/repository/ysq-dev/</repository.url>-->
    </properties>
  </profile>
  <!--测试-->
  <profile>
    <id>test</id>
    <properties>
      <profiles.active>test</profiles.active>
      <!--<repository.id>test</repository.id>
      <repository.name>test Repository</repository.name>
      <repository.url>https://nexus.pharmakeyring.com/repository/ysq-test/</repository.url>-->
    </properties>
  </profile>
  <!--正式-->
  <profile>
    <id>prod</id>
    <properties>
      <profiles.active>prod</profiles.active>
      <!--<repository.id>prod</repository.id>
      <repository.name>prod Repository</repository.name>
      <repository.url>https://nexus.pharmakeyring.com/repository/ysq-public/</repository.url>-->
    </properties>
  </profile>
</profiles>
​
<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
      <includes>
        # 这个名字是自定义统一的
        <include>application-${profiles.active}.yml</include>
        <include>application.yml</include>
      </includes>
    </resource>
  </resources>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-resources-plugin</artifactId>
      <version>2.7</version>
      <configuration>
        <delimiters>
          <delimiter>@</delimiter>
        </delimiters>
        <useDefaultDelimiters>false</useDefaultDelimiters>
      </configuration>
    </plugin>
  </plugins>
</build>
​
​
​
spring:
  application:
    name: smilemall-product
  profiles:
    active: @profiles.active@

Ubuntu

CentOS

没有 ifconfig

说明没有安装工具 net-tools。

解决方法1
yum install net-tools

ifconfig 不显示 ip,ping 不通了

原因和解决方法1

很有可能是显示了,但是你因为屏幕太小看不到,所以可以把结果写入文件。

ifconfig > 1.txt
head -n 15 1.txt
rm 1.txt
原因和解决方法2

可能是 CD/DVD 的 iso 移动位置了。

右键主机,选择设置,选择 CD/DVD(IDE),确认这个 iso 的地址是否存在。

原因和解决方法3

如果 iso 的地址是对的,那就点“使用武力驱动器”,让他自动检测也可以;或者点高级,修改虚拟设备节点。一般就是 IDE 0:0 或 IDE 1:0 或 SATA 0:1。

Redisson

Redis连接不上

启动项目的时候报错,大概意思就是说什么密码错误,连接不上。

原因和解决方法1

有可能是 Redis 没设置密码的原因,给 Redis 加上密码可能就能启动了。

Windows远程桌面连接

文件复制不进去

当我们连接 Windows服务器的时候,想把文件复制进去,但是发现放不进去,是因为“连接设置”没做盘符挂载。之后就能在服务器里面看到了。

  • 22
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值