BeanCreationException:创建名为“userRepository”

我尝试实现这个用户管理模板并使其适应我的需要,但 Springboot 应用程序不再启动,我遇到了这个错误:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Post-processing of merged bean definition failed; nested exception is java.lang.NoClassDefFoundError: javax/persistence/SynchronizationType

我无法弄清楚出了什么问题。请帮忙?


回首忆惘然
浏览 224回答 3
3回答

拉莫斯之舞

我认为您必须从 pom.xml<dependency>&nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; <artifactId>hibernate-core</artifactId>&nbsp; &nbsp; <version>4.1.4.Final</version></dependency>Spring Boot 2.1已经有Hibernate依赖项而且它使用Hibernare v.5所以这里可能有一些问题Hibernate v.4而且我没有在你正在关注的教程中找到这样的依赖项UPD 例外情况org.springframework.beans.factory.BeanCreationException:创建名为“entityManagerFactory”的 bean 在类路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class] 中定义时出错:调用 init 方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; 嵌套异常是 org.hibernate.cfg.beanvalidation.IntegrationException:激活 Bean 验证集成时出错阅读这个( jaxb-api的最新版本是 2.3.1)。作为一种选择,我还建议您尝试将 a 添加@EnableTransactionManagement到配置类UPD2我终于设法重现了异常(...激活 Bean 验证集成时出错) 在我的环境中并找出问题的根源。由于您已经添加了此依赖项:<dependency>&nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; <artifactId>spring-boot-starter-validation</artifactId></dependency>您不应添加任何其他验证依赖项。所以要摆脱这个问题,你必须删除这个:<dependency>&nbsp; &nbsp; <groupId>javax.validation</groupId>&nbsp; &nbsp; <artifactId>validation-api</artifactId>&nbsp; &nbsp; <version>1.1.0.Final</version></dependency>

精慕HU

您问题的根本原因是不正确的依赖关系。您可以从 pom.xml 中注释掉以下依赖项:<dependency>&nbsp; &nbsp; <groupId>javax.validation</groupId>&nbsp; &nbsp; <artifactId>validation-api</artifactId>&nbsp; &nbsp; <version>1.1.0.Final</version></dependency><dependency>&nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; <artifactId>hibernate-validator</artifactId>&nbsp; &nbsp; <version>5.4.1.Final</version></dependency><dependency>&nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; <artifactId>hibernate-core</artifactId>&nbsp; &nbsp; <version>4.1.4.Final</version></dependency>接下来你可以mvn dependency:tree在你的项目上做一个,并看到它org.springframework.boot:spring-boot-starter-web:jar:2.1.0.RELEASE传递了这两个组件的正确版本:org.hibernate.validator:hibernate-validator:jar:6.0.13.Finaljavax.validation:validation-api:jar:2.0.1.Finalorg.springframework.boot:spring-boot-starter-data-jpa 传递性拉入:org.hibernate:hibernate-core:jar:5.3.7.Final数据库上的存储库操作在此设置下可以正常工作。pom.xml<parent>&nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; <artifactId>spring-boot-starter-parent</artifactId>&nbsp; &nbsp; <version>2.1.0.RELEASE</version>&nbsp; &nbsp; <relativePath/> <!-- lookup parent from repository --></parent><properties>&nbsp; &nbsp; <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>&nbsp; &nbsp; <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>&nbsp; &nbsp; <java.version>1.8</java.version></properties><dependencies>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-web</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-devtools</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <scope>runtime</scope>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-test</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <scope>test</scope>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-thymeleaf</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-tomcat</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <scope>provided</scope>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-data-jpa</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.h2database</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>h2</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-data-rest</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-security</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.thymeleaf.extras</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>thymeleaf-extras-springsecurity4</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>3.0.1.RELEASE</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-actuator</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.security</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-security-taglibs</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-mail</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>commons-beanutils</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>commons-beanutils</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- bootstrap and jquery -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.webjars</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>bootstrap</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>3.3.7</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.webjars</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jquery</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>3.2.1</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- mysql connector -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>mysql</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>mysql-connector-java</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <scope>runtime</scope>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.icegreen</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>greenmail</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.5.5</version>&nbsp; &nbsp; &nbsp; &nbsp; <scope>test</scope>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!--<dependency>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<groupId>javax.validation</groupId>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<artifactId>validation-api</artifactId>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<version>1.1.0.Final</version>-->&nbsp; &nbsp; <!--</dependency>-->&nbsp; &nbsp; <!--<dependency>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<groupId>org.hibernate</groupId>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<artifactId>hibernate-validator</artifactId>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<version>5.4.1.Final</version>-->&nbsp; &nbsp; <!--</dependency>-->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-validation</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>commons-codec</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>commons-codec</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.10</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>commons-beanutils</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>commons-beanutils</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.9.3</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!--<dependency>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<groupId>org.hibernate</groupId>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<artifactId>hibernate-core</artifactId>-->&nbsp; &nbsp; &nbsp; &nbsp; <!--<version>4.1.4.Final</version>-->&nbsp; &nbsp; <!--</dependency>--></dependencies>依赖树[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.1.0.RELEASE:compile[INFO] |&nbsp; +- org.hibernate.validator:hibernate-validator:jar:6.0.13.Final:compile[INFO] |&nbsp; |&nbsp; +- javax.validation:validation-api:jar:2.0.1.Final:compile[INFO] |&nbsp; |&nbsp; +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile[INFO] |&nbsp; |&nbsp; \- com.fasterxml:classmate:jar:1.4.0:compile

慕森王

有人告诉我问题是我需要一个实际的邮件服务器一起运行。我不知道。对您来说,这听起来像是这次崩溃的合理原因吗?有关如何设置电子邮件服务器并将其链接到 Maven 项目的优秀教程的任何链接?我找不到任何。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java