Java后端项目常见问题

项目启动到一半停止

(1)可能没加依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

(2)可能maven生命周期test失败,需要跳过可加

<plugin><!--编译跳过测试文件检查的生命周期-->
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
          <skip>true</skip>
      </configuration>
</plugin>

存在两个一样方式的请求路径

java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path ‘xxxx’

kafka与springboot版本不兼容

Caused by: java.lang.TypeNotPresentException: Type org.springframework.kafka.listener.RecordInterceptor not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) ~[na:1.8.0_311]
org.springframework.core.MethodParameter.getGenericParameterType(MethodParameter.java:513) ~[spring-core-5.2.14.RELEASE.jar:5.2.14.RELEASE]

原因:kafka需要依赖这个spring-core-5.2.14.RELEASE.jar:5.2.14.RELEASE,所以要注spring-kafka,spring-boot-starter-parent,kafka-clients三者版本

比如

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

       	<dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
            <version>2.4.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>2.4.1</version>
        </dependency>

Maven3.8.5版本过高

Error injecting constructor, java.lang.NoSuchMethodError: org.apache.maven.model.validation

解决:替换成maven3.6.3就好了

依赖导入失败

The POM for com.dzh:grpc-lib:jar:1.0-SNAPSHOT is missing, no dependency information available

Failed to execute goal on project grpc-server: Could not resolve dependencies for project com.dzh:grpc-server:jar:1.0-SNAPSHOT: Failure to find com.dzh:grpc-lib:jar:1.0-SNAPSHOT in https://maven.aliyun.com/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of snapshots has elapsed or updates are forced

Could not find artifact com.dzh:grpc-lib:pom:1.0-SNAPSHOT in snapshots (https://maven.aliyun.com/nexus/content/groups/public)

意思很明显,就是依赖没找到。去仓库发现就这么几个玩意,并没有对应的jar包
Java后端项目常见问题_第1张图片
所以我们删除仓库的该包,重新对该module进行install一下
Java后端项目常见问题_第2张图片
我建议就是,在maven仓库把该项目的依赖都删除,重新在父工程install

ServiceTask一直循环

原因是不知道怎么创建出一个这个玩意
在这里插入图片描述

Lombok的坑

问题: 今天使用了一个实体类去映射数据库报这个错
Cannot determine value type from string “xxx”

数据库表字段类型与Java类里面都成员属性类型不一致,然后检查MyBatis中xml各自配置,感觉都没问题。

原因: 是在Java类中使用了Lombok的注解@Builder和@Data,导致JavaBean中没有无参构造器。

解决: 只需再添加两个Lombok注解@NoArgsConstructor和@AllArgsConstructor即可。

预期值与结果不一致

返回的是一个值,但如果数据库查出了多条数据就会报这个错误:
Expected one result (or null) to be returned by selectOne(), but found: 2

Mybatis-plus的this.getOne()方法也可能报这个错

解决:只需要保证数据库只查出一条数据即可。

json反序列化错误

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “id”

原因是我的数据库里的json有id这个k-v,但我的实体没有这个id属性

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `com.hnxh.system.domain.vo.FileInfoVO` from Array value (token `JsonToken.START_ARRAY`) at [Source: (PushbackInputStream); line: 1, column: 1504] (through reference chain: com.hnxh.business.domain.dto.employee.EmployeeDimissionDTO["relieveFile"])

原因是传递的json中 relieveFile:[],而我后端实体中 private FileInfoVO relieveFile;

mysql

一.获取公钥

java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

url后加:allowPublicKeyRetrieval=true允许客户端从服务器获取公钥

二.数据库驱动版本

Could not create connection to database server. Attempted reconnect 3 times. Giving up.

原因是我的mysql是8.0的,而数据库驱动版本太低,所以改为

        
        
            mysql
            mysql-connector-java
            8.0.20
        

三.数据库时区

java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the ‘serverTimezone’ configuration property) to use a more specifc time zone value if you want to utilize time zone support.

url后加serverTimezone=GMT%2B8时区问题

四.SSL

javax.net.ssl.SSLException
MESSAGE: closing inbound before receiving peer’s close_notify

useSSL=false

nacos服务注册失败

Error processing condition on com.alibaba.cloud.nacos.discovery.reactive.NacosReactiveDiscoveryClientConfiguration.nacosReactiveDiscoveryClient

出现这种情况可能是依赖版本冲突

 <dependency>
     <groupId>com.alibaba.cloud</groupId>
     <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
     <version>2.2.1.RELEASE</version>
 </dependency>

poi依赖重复

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/apache/poi/common/Duplicatable

很明显,poi依赖重复了,可能导入了两种底层是poi的依赖

flyway不小心删除了中间的脚本数据

To allow executing this migration, set -outOfOrder=true.

不小心删除了中间脚本的数据,那么如果设置了有序迁移,就会报错

所以设置为无序迁移,out-of-order默认为false

flyway.out-of-order: true

SimpleGrantedAuthority

A granted authority textual representation is required

原因是SimpleGrantedAuthority的构造方法,有断言,role不能为空:
Assert.hasText(role, “A granted authority textual representation is required”);

QueryDSL找不到Q开头的实体

需要导入依赖:

<!-- QueryDSL 依赖 -->
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
        </dependency>

导入插件:

<build>
        <plugins>
            <!-- QueryDSL 编译插件 -->
            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>1.1.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/generated-sources/java</outputDirectory>
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

然后对实体模块重新package

代码中有这个包,而build时显示没有

Java后端项目常见问题_第3张图片
各种清缓存、重启都没用。

试试重新clean、package

待续。。。

你可能感兴趣的:(bug,spring,maven,java)