我找不到为什么在Spring Boot应用程序中发生此错误的java.lang.IncompatibleClassChangeError:null

时间:2020-01-29 07:02:48

标签: java spring spring-boot repository

我使用Spring Boot,Hibernate,Postgres。我在使用spring boot项目时遇到麻烦。但是我无法弄清楚问题是什么以及何时会出现。无法注入我的存储库。有人知道我做错了吗?在这种情况下,可能不会注入存储库。 我正在使用spring-boot 2.2.2.RELEASE

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-01-29 11:25:07.089 ERROR 9428 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'blocktestServiceImpl': Unsatisfied dependency expressed through field 'blocktestDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blocktestDao': Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$186/1303239496.getObject(Unknown Source)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at uz.owl.lmsapp.LmsApp.main(LmsApp.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blocktestDao': Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$186/1303239496.getObject(Unknown Source)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
    ... 25 common frames omitted
Caused by: java.lang.IncompatibleClassChangeError: null
    at org.springframework.data.jpa.util.JpaMetamodel.lambda$isSingleIdAttribute$4(JpaMetamodel.java:94)
    at org.springframework.data.jpa.util.JpaMetamodel$$Lambda$707/451217154.test(Unknown Source)
    at java.util.Optional.filter(Optional.java:178)
    at org.springframework.data.jpa.util.JpaMetamodel.isSingleIdAttribute(JpaMetamodel.java:94)
    at org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl.lambda$new$2(JpaPersistentPropertyImpl.java:110)
    at org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl$$Lambda$697/663202040.get(Unknown Source)
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:212)
    at org.springframework.data.util.Lazy.get(Lazy.java:94)
    at org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl.isIdProperty(JpaPersistentPropertyImpl.java:141)
    at org.springframework.data.jpa.mapping.JpaPersistentEntityImpl.returnPropertyIfBetterIdPropertyCandidateOrNull(JpaPersistentEntityImpl.java:72)
    at org.springframework.data.jpa.mapping.JpaPersistentEntityImpl.returnPropertyIfBetterIdPropertyCandidateOrNull(JpaPersistentEntityImpl.java:39)
    at org.springframework.data.mapping.model.BasicPersistentEntity.addPersistentProperty(BasicPersistentEntity.java:218)
    at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:538)
    at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:506)
    at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:705)
    at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:374)
    at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator$$Lambda$703/1886151113.accept(Unknown Source)
    at java.util.Collections$SingletonSet.forEach(Collections.java:4826)
    at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:548)
    at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:506)
    at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:705)
    at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:374)
    at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator$$Lambda$703/1886151113.accept(Unknown Source)
    at java.util.Collections$SingletonSet.forEach(Collections.java:4826)
    at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:548)
    at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:506)
    at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:705)
    at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:374)
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:248)
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:191)
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:85)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$4(RepositoryFactoryBeanSupport.java:295)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport$$Lambda$644/260816667.accept(Unknown Source)
    at java.util.Optional.ifPresent(Optional.java:159)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:295)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
    ... 36 common frames omitted
@Repository
public interface BlocktestDao extends JpaRepository<Blocktest, Long> {
}
@Entity
@Getter
@Setter
@Table(name = "blocktest")
public class Blocktest {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String title;

    @OneToMany(mappedBy = "blocktest")
    private  List<BlocktestSubject> blocktestSubjects = new ArrayList<>();

    @OneToMany(mappedBy = "blocktest")
    private  List<BlocktestGroup> blocktestGroups = new ArrayList<>();

    @Override
    public String toString() {
        return "Blocktest{" +
                "id=" + id +
                ", title='" + title + '\'' +
                '}';
    }
}

@Service
public class BlocktestServiceImpl implements BlocktestService {

    @Autowired  private StudentSubjectLevelService priorityService;
    @Autowired  private BlocktestDao blocktestDao;
    @Autowired  private StudentGroupDao studentGroupDao;


    /**
     * Please provide valid student list
     * @param students
     * @param title
     * @return
     */
    @Override
    @Transactional
    public BlocktestDto createBlocktest(List<Student> students, String title) {

        return null;
    }
}

这是我的pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>uz.owl</groupId>
    <artifactId>LmsApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>2.2.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>3.2.0</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-envers -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
        </dependency>


        <!--TODO ===================== SECURITY ===========================-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.10.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.10.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.10.5</version>
        </dependency>

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


        <!--TODO===================<WEB>================-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>


        <!--TODO=================<DEV TOOL>=================-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>


        <!--TODO===========<SPRING DATA POSTGRES>=============-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>



        <!--TODO================<TEST DEP>=====================-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--TODO==============< LOGGING >===================-->
        <!-- https://mvnrepository.com/artifact/ch.qos.logback.contrib/logback-mongodb-core -->
        <dependency>
            <groupId>ch.qos.logback.contrib</groupId>
            <artifactId>logback-mongodb-core</artifactId>
            <version>0.1.5</version>
        </dependency>

        <!--TODO===================< POI >=====================-->
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/ooxml-schemas -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>ooxml-schemas</artifactId>
            <version>1.4</version>
            <exclusions>
                <exclusion>
                    <artifactId>org.apache.xmlbeans</artifactId>
                    <groupId>xmlbeans</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <repositories>
        <repository>
            <id>jboss repo</id>
            <name>jboss repo</name>
            <url>https://jcenter.bintray.com/</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

更新: 现在我发现了另一件事。如果我删除此关系

    @OneToMany(mappedBy = "blocktest")
    private  List<BlocktestSubject> blocktestSubjects = new ArrayList<>();

    @OneToMany(mappedBy = "blocktest")
    private  List<BlocktestGroup> blocktestGroups = new ArrayList<>();

项目可以正确启动

这是我的其他实体:

@Getter
@Setter
@Table(name = Tables.BLOCKTEST_SUBJECT)
public class BlocktestSubject {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "subject_id", nullable = false, insertable = false, updatable = false)
    private Long subjectId;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "subject_id")
    private Subject subject;

    @Column(name = "blocktest_id", nullable = false, insertable = false, updatable = false)
    private Long blocktestId;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "blocktest_id")
    private Blocktest blocktest;

    @OneToMany(mappedBy = "blocktestSubject", fetch = FetchType.EAGER)
    private List<BSPCount> bspCounts;

    @OneToMany(mappedBy = "blocktestSubject")
    private final List<Rule> rules = new ArrayList<>();
}
@Entity
@Getter
@Setter
public class BlocktestGroup {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "blocktest_id", nullable = false, insertable = false, updatable = false)
    private Long blocktestId;
    @ManyToOne
    @JoinColumn(name = "blocktest_id")
    private Blocktest blocktest;

    @Column(name = "file_id", insertable = false, updatable = false, nullable = false)
    private Long fileId;
    @OneToOne
    @JoinColumn(name = "file_id")
    private TFile tFile;

}

1 个答案:

答案 0 :(得分:0)

在将spring-boot项目从2.1.1.RELEASE升级到2.3.4.RELEASE时,我遇到了类似的问题。我找不到任何在线参考来提供帮助。 我尝试将Java版本从8升级到15,此问题已解决。尝试升级您的Java版本并共享,如果有帮助的话。