当前位置: 首页 > 知识库问答 >
问题:

激活Bean验证集成时出现Spring Boot错误

翟弘
2023-03-14
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.elutil可从以下位置获得:

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
    <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>
# ===============================
# = 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

共有1个答案

云洋
2023-03-14

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

通常,servlet、jsp和el库应该由您的容器提供。因此,我会考虑将 提供的 添加到不同的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库实现,拥有第二个库可能会导致类路径问题。

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

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

Hibernate Validator 5.x->Bean Validation 1.1(JSR 349)->EL2.2

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

 类似资料:
  • 本文向大家介绍SpringBoot集成kaptcha验证码,包括了SpringBoot集成kaptcha验证码的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了SpringBoot集成kaptcha验证码的具体代码,供大家参考,具体内容如下 1.kaptcha相关介绍 Kaptcha是一个基于SimpleCaptcha的验证码开源项目。 2.集成方案 ①pom.xml中配置依赖 ②配置

  • 本文向大家介绍SpringBoot集成JWT实现token验证的流程,包括了SpringBoot集成JWT实现token验证的流程的使用技巧和注意事项,需要的朋友参考一下 JWT官网: https://jwt.io/ JWT(Java版)的github地址:https://github.com/jwtk/jjwt 什么是JWT Json web token (JWT), 是为了在网络应用环境间传递

  • 我试图将Bean验证api-javax.Validation和hibernate-validator与Spring MVC应用程序集成在一起。我可以看出,当REST控制器方法不使用BindingResult参数时,服务器会正常启动并工作。但是当我在函数签名中使用BindingResult arg时,我会看到如下运行时错误 代码: .....}

  • 我刚开始使用hibernate,不太确定我的应用程序出了什么问题。所以我有两个模块:核心模块和网站模块。 模块核心拥有所有的实体,daos和所有的数据库工作。所有的DAO继承一个AbstractDAO。 模块网站做所有前端的东西,如jsps,mvc控制器...它是一个支持Spring框架的maven模块。 我试图实现第二级缓存使用ehache工厂。 组织。springframework。豆。工厂B

  • 登录后,它生成了一个哈希值,但仍然给出错误“Some problem currened!try tain”。

  • null 代码构建良好,但当我运行它时,它会在下面抛出错误