【问题标题】:Spring Boot Error activating Bean Validation integrationSpring Boot 错误激活 Bean Validation 集成
【发布时间】:2020-12-22 20:15:45
【问题描述】:

我正在尝试启动我的网络应用程序,但出现了这两个错误:

2020-12-22 20:46:25.769  INFO 23060 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2020-12-22 20:46:26.161 ERROR 23060 --- [           main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
2020-12-22 20:46:26.162  WARN 23060 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
2020-12-22 20:46:26.162  INFO 23060 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2020-12-22 20:46:26.177  INFO 23060 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2020-12-22 20:46:26.179  INFO 23060 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-12-22 20:46:26.191  INFO 23060 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-12-22 20:46:26.207 ERROR 23060 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

这里是最终错误输出的描述:


说明:

试图调用一个不存在的方法。尝试是从以下位置进行的:

javax.el.ELManager.getExpressionFactory(ELManager.java:38)

以下方法不存在:

javax.el.ELUtil.getExpressionFactory()Ljavax/el/ExpressionFactory;

该方法的类 javax.el.E​​LUtil 可从以下位置获得:

jar:file:/C:/Users/chafy/Desktop/backend/lib/javax.servlet.jsp.jar!/javax/el/ELUtil.class
jar:file:/C:/Users/chafy/.m2/repository/org/glassfish/jakarta.el/3.0.3/jakarta.el-3.0.3.jar!/javax/el/ELUtil.class
jar:file:/C:/Users/chafy/.m2/repository/javax/el/javax.el-api/3.0.0/javax.el-api-3.0.0.jar!/javax/el/ELUtil.class
jar:file:/C:/Users/chafy/.m2/repository/org/glassfish/javax.el/3.0.0/javax.el-3.0.0.jar!/javax/el/ELUtil.class

类层次结构是从以下位置加载的:

javax.el.ELUtil: file:/C:/Users/chafy/Desktop/backend/lib/javax.servlet.jsp.jar

行动:

更正应用程序的类路径,使其包含一个兼容的 javax.el.E​​LUtil 版本


这是我的依赖:

    <dependencies>
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>annotations</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.11.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <scope>runtime</scope>
            <version>0.11.2</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <scope>runtime</scope>
            <version>0.11.2</version>
        </dependency>
        <!-- TimeAgo related dependencies-->
        <dependency>
            <groupId>com.github.marlonlom</groupId>
            <artifactId>timeago</artifactId>
            <version>4.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
            <version>2.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>5.4.26.Final</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
            <version>2.12.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.el</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.4.3.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>
    </dependencies>

这里是我的 application.properties :

# ===============================
# = DATA SOURCE
# ===============================
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/cuberil?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=Charigan99./
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.initialization-mode=always
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.hbm2ddl.auto=update
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
# Mail Properties
spring.mail.host=smtp.mailtrap.io
spring.mail.port=25
spring.mail.username=<your-smtp-username>
spring.mail.password=<your-smtp-password>
spring.mail.protocol=smtp

我试图通过添加许多依赖项来解决它,但什么也没有。有人说是servlet版本问题,其实不是。

【问题讨论】:

  • 嗨,您能分享一下您的数据库课程吗?
  • @AndreMoraes 我已经编辑了我的帖子,你可以看到它!
  • 你运行的tomcat容器是什么版本的?
  • @hooknc 这是 Tomcat 9

标签: java spring-boot hibernate validation javabeans


【解决方案1】:

所以,我不知道确切的问题,但也许我可以给你一些东西来看看和/或尝试。

一般来说,servlet、jsp 和 el 库应该由您的容器提供。因此,我会考虑将 &lt;scope&gt;provided&lt;/scope&gt; 添加到您的不同 servlet 库中:

<!-- Provided by Tomcat Container -->
<dependency>
    <groupId>javax.el</groupId>
    <artifactId>javax.el-api</artifactId>
    <version>3.0.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
    <scope>provided</scope>
</dependency>

由于您使用的是 Tomcat,我将删除 org.glassfish.javax.el 库的直接使用。我认为每个容器都提供了自己的 el 库实现,并且拥有第二个库可能会导致类路径问题。

(很可能)从 pom.xml 中删除:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.el</artifactId>
    <version>3.0.0</version>
</dependency>

Hibernate Validator 也有点痛苦。 From this answer on a similar problem:

Hibernate Validator 6.x -> Bean Validation 2.0 (JSR 380) -> EL3.0

Hibernate 验证器 5.x -> Bean 验证 1.1 (JSR 349) -> EL2.2

Bean Validation 1.0 (JSR 303) ->(我不确定)

因此,理论上,您应该使用 Hibernate Validator 6 而不是像现在这样的版本 5。

【讨论】:

  • 感谢您的回答,但我不知道我的依赖项中的 servlet 库。你能告诉我其中的一些吗?我要检查 Hibernate Validator !
  • 更新了答案以显示应该提供哪些库(最有可能)以及应该删除哪些库。
  • 好的。但不幸的是,错误仍然存​​在。我尝试搜索解决方案已经有几个小时了。好痛啊啊啊。
猜你喜欢
  • 2013-05-11
  • 2013-06-20
  • 1970-01-01
  • 2020-04-27
  • 1970-01-01
  • 2016-12-15
  • 1970-01-01
  • 1970-01-01
  • 2019-07-30
相关资源
最近更新 更多