【问题标题】:STS / Spring Boot - Running Spring Boot Project inside IDE is using test dependenciesSTS / Spring Boot - 在 IDE 中运行 Spring Boot 项目正在使用测试依赖项
【发布时间】:2017-06-24 08:00:01
【问题描述】:

测试build.gradle中的依赖关系,

testCompile('org.flywaydb:flyway-core')
testCompile('org.hsqldb:hsqldb')
testCompile('org.springframework.boot:spring-boot-starter-test')

当我以Spring Boot App 运行应用程序时,出现错误:

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.api.FlywayException: Found non-empty schema [dbo] without metadata table! Use baseline() or set baselineOnMigrate to true to initialize the metadata table.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    ...
Caused by: org.flywaydb.core.api.FlywayException: Found non-empty schema [dbo] without metadata table! Use baseline() or set baselineOnMigrate to true to initialize the metadata table.
    at org.flywaydb.core.Flyway$1.execute(Flyway.java:1035) ~[flyway-core-3.2.1.jar:?]
    at org.flywaydb.core.Flyway$1.execute(Flyway.java:1006) ~[flyway-core-3.2.1.jar:?]
    at org.flywaydb.core.Flyway.execute(Flyway.java:1418) ~[flyway-core-3.2.1.jar:?]
    at org.flywaydb.core.Flyway.migrate(Flyway.java:1006) ~[flyway-core-3.2.1.jar:?]
    at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    ... 16 more

为什么在 IDE 中运行项目时会使用测试依赖项? 或者我在这里遗漏了什么?

非常感谢任何帮助:)

注意:

1 - 如果我在 IDE 外使用 java -jar [put path here] 或 gradle boot run 运行它,它运行良好

2 - 我尝试过刷新 gradle 项目、清理项目等。

3 - 使用 STS 版本3.8.3.RELEASE

【问题讨论】:

    标签: spring-boot spring-tool-suite flyway


    【解决方案1】:

    这是 Gradle Eclipse 支持的一个已知问题。从我记事起,这一直是个问题。这是对 Gradle 的 STS 旧版支持中的一个问题,并且在 BuildShip 中仍然是一个问题。

    由于 STS 旧版支持处于“低维护”模式,因此不太可能在那里得到修复。但在 BuildShip 中有希望。在 Eclipse bugzilla 中为此打开了一个 bug。该bug最近got moved到github。

    我建议您前往 github 问题并在那里添加您的声音/投票。

    【讨论】:

    • 感谢您提供的信息。在那里添加了投票。接受为答案并等待修复。希望他们尽快做点什么:)
    【解决方案2】:

    我的猜测:您的 hsql 数据库是持久的,并且尚未由 Flyway 初始化,并且数据库/模式“dbo”已经创建了一些表?

    【讨论】:

    • 不存在表。它具有测试依赖性。我认为这意味着,在运行应用程序时不应使用那些jars。它应该只在我运行测试时使用。
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2019-03-14
    • 1970-01-01
    • 2019-07-28
    • 2020-09-22
    • 1970-01-01
    相关资源
    最近更新 更多