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

上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:

强金鑫
2023-03-14

我正在尝试用mysql和flyway运行我的Spring项目引导

我的环境:

>

  • Linux 18.04

    Java 1.8.0_201

    <properties>
        <java.version>1.8</java.version>
    </properties>
    
    <dependencies>
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>
    
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
    
        <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>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>2.0.2</version>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    

    application.yml

    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/tutorial_bd?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
        username: root
        password:
      jpa:
        show-sql: true
        hibernate:
          ddl-auto: validate
          naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
        properties:
          hibernate:
            dialect: org.hibernate.dialect.MySQL5InnoDBDialect
      flyway:
        url: jdbc:mysql://localhost:3306/tutorial_bd
        user: "root"
        password:
        baselineOnMigrate: true
        check-location: true
        locations: classpath:db/migration
        enabled: true
    

    v1__init.sql

    CREATE TABLE users (
      id bigint(20) NOT NULL AUTO_INCREMENT,
      username varchar(100) NOT NULL,
      first_name varchar(50) NOT NULL,
      last_name varchar(50) DEFAULT NULL,
      PRIMARY KEY (id),
      UNIQUE KEY UK_username (username)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    

    user.java

    package com.mhanzouli.tutorial.domain;
    
    import javax.persistence.*;
    import javax.validation.constraints.NotBlank;
    import javax.validation.constraints.Size;
    
    @Entity
    @Table(name = "users")
    public class User {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Long id;
    
        @NotBlank
        @Column(unique = true)
        @Size(min = 1, max = 100)
        private String username;
    
        @NotBlank
        @Size(max = 50)
        private String firstName;
    
        @Size(max = 50)
        private String lastName;
    
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        public String getUsername() {
            return username;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    
        public String getFirstName() {
            return firstName;
        }
    
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    }
    
    mvn spring-boot:run
    
    2020-06-20 21:19:54.540  INFO 13594 --- [           main] c.m.tutorial.TutorialApplication         : Starting TutorialApplication on marwen with PID 13594 (/home/marwen/Bureau/projects/tutorial/target/classes started by marwen in /home/marwen/Bureau/projects/tutorial)
    2020-06-20 21:19:54.543  INFO 13594 --- [           main] c.m.tutorial.TutorialApplication         : No active profile set, falling back to default profiles: default
    2020-06-20 21:19:55.337  INFO 13594 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
    2020-06-20 21:19:55.364  INFO 13594 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 19ms. Found 0 JPA repository interfaces.
    2020-06-20 21:19:55.962  INFO 13594 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
    2020-06-20 21:19:55.971  INFO 13594 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2020-06-20 21:19:55.971  INFO 13594 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.36]
    2020-06-20 21:19:56.045  INFO 13594 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2020-06-20 21:19:56.046  INFO 13594 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1452 ms
    2020-06-20 21:19:56.196  INFO 13594 --- [           main] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 6.4.4 by Redgate
    2020-06-20 21:19:56.310  INFO 13594 --- [           main] o.f.c.internal.database.DatabaseFactory  : Database: jdbc:mysql://localhost:3306/tutorial_bd (MySQL 5.5)
    2020-06-20 21:19:56.366  WARN 13594 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.license.FlywayEditionUpgradeRequiredException: Flyway Pro Edition or MariaDB upgrade required: MariaDB 10.1 is no longer supported by Flyway Community Edition, but still supported by Flyway Pro Edition.
    2020-06-20 21:19:56.369  INFO 13594 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
    2020-06-20 21:19:56.382  INFO 13594 --- [           main] ConditionEvaluationReportLoggingListener : 
    
    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2020-06-20 21:19:56.392 ERROR 13594 --- [           main] o.s.boot.SpringApplication               : Application run failed
    
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.license.FlywayEditionUpgradeRequiredException: Flyway Pro Edition or MariaDB upgrade required: MariaDB 10.1 is no longer supported by Flyway Community Edition, but still supported by Flyway Pro Edition.
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
            at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
            at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
            at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
            at com.mhanzouli.tutorial.TutorialApplication.main(TutorialApplication.java:10) [classes/:na]
    Caused by: org.flywaydb.core.internal.license.FlywayEditionUpgradeRequiredException: Flyway Pro Edition or MariaDB upgrade required: MariaDB 10.1 is no longer supported by Flyway Community Edition, but still supported by Flyway Pro Edition.
            at org.flywaydb.core.internal.database.base.Database.ensureDatabaseNotOlderThanOtherwiseRecommendUpgradeToFlywayEdition(Database.java:173) ~[flyway-core-6.4.4.jar:na]
            at org.flywaydb.core.internal.database.mysql.MySQLDatabase.ensureSupported(MySQLDatabase.java:287) ~[flyway-core-6.4.4.jar:na]
            at org.flywaydb.core.Flyway.execute(Flyway.java:514) ~[flyway-core-6.4.4.jar:na]
            at org.flywaydb.core.Flyway.migrate(Flyway.java:159) ~[flyway-core-6.4.4.jar:na]
            at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar:2.3.1.RELEASE]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
            ... 19 common frames omitted
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  10.089 s
    [INFO] Finished at: 2020-06-20T21:19:56+01:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.3.1.RELEASE:run (default-cli) on project tutorial: Application finished with exit code: 1 -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    
  • 共有1个答案

    翟修明
    2023-03-14

    例外情况显示“不再支持MariaDB 10.1”。使用Maria DB的较新版本,例如当前版本10.5.3,以及相应版本的JDBC驱动程序。

     类似资料:
    • 问题是,每次我运行该项目时,都会从org中发现错误。springframework。豆。工厂“未满足的支出”异常弹出窗口。 我已经尝试了几个相关的问题和答案,但是问题还没有解决。 FieldDataService。JAVA FieldDataServiceImpl。JAVA FieldDataDao。JAVA FieldDataDaoImpl.java 现场数据。JAVA 现场数据。xml ...

    • 我正在开发一个Spring引导应用程序。在尝试了许多解决方案后,它没有得到解决。请帮助: 控制台:org。springframework。豆。工厂UnsatisfiedPendencyException:创建名为“doctorController”的bean时出错:通过字段“doctorService”表示未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂Unsatis

    • 我所有的春靴项目都不会突然起作用。我创建了一个新的Spring Boot项目,没有添加任何类。当我开始这个项目时,我还是有一个错误。 以下是错误: 我已经检查了现有的类似错误,但它总是与代码有关。在我的例子中,没有添加代码。 我已经编辑了这个项目。实际上,这个项目做得很好。现在我认为在spring依赖项中有一个混合

    • 当没有堆栈跟踪时,我如何知道问题是什么?我可以启用某些选项吗?我刚刚用spring初始化器创建了一个小项目,这就是我得到的 更新的日志(带有调试标志)

    • 我在做一个春靴项目。然后我尝试将mysql数据库连接到那个项目。我得到了名为“hikaripool-1-exception distry pool initialization”的错误。 这是整个StackTrace。

    • 在使用PostgreSQL数据库启动sprint boot应用程序时出现错误,我试图找到一个解决方案,但到目前为止还没有找到。 这里有个错误: 2018-03-29 17:48:17.945警告13508--[main]ationConfigEmbeddedWebApplicationContext:上下文初始化过程中遇到异常-取消刷新尝试:org.springFramework.Beans.Fa