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

STS/Spring Boot——在IDE中运行Spring Boot项目使用测试依赖项

赫连晋
2023-03-14

中测试代码依赖项。格雷德尔,

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-如果我使用java-jar[put path here]或gradle boot run在IDE之外运行它,它运行得很好

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

3-使用STS版本3.8.3。RELEASE

共有2个答案

程正阳
2023-03-14

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

郑茂材
2023-03-14

这是Gradle Eclipse支持的一个已知问题。从我记事起,这一直是个问题。这是对Gradle的STS遗留支持中的一个问题,在BuildShip中也是一个问题。

由于STS遗留支持处于“低维护”模式,因此不太可能得到修复。但在建筑中有希望。Eclipse bugzilla中有一个漏洞。该漏洞最近被转移到github。

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

 类似资料:
  • 我有一个Spring启动应用程序,需要: 可以在servlet容器中作为战争部署 通过“mvn Spring Boot:运行”可运行`` 我还希望通过右键单击并运行它,能够在我的IDE(Eclipse或IntelliJ IDEA社区)中运行此应用程序。 下面是我的pom.xml的有趣部分(注意,我不是从spring boot starter父pom继承的): 这是我的: 在IDE中运行main时,

  • 我有几个繁重的Spring集成测试(是的,这不是最好的方法,我没有时间正确地模拟所有外部dep) 下面是测试的典型注释 由于以下原因,测试会定期失败: 这里有两个问题:1、让测试共存的正确方式是什么?我在surefire插件中设置了forkCount=0。好像有帮助 2.1. 在每次测试期间,我实际上不需要启动所有的

  • 我有一个基本的SpringBoot应用程序。使用Spring初始值设定项、嵌入式Tomcat、Thymeleaf模板引擎,并将包作为可执行的JAR文件。是一个带有Spring Boot的多模块项目,该项目将有3个模块。这里是父模块pom。xml 这里是模块核心 这里是模块web: 从父根目录,我使用以下方法生成所有模块: 但问题是tdk-web-0.0.2-SNAPSHOT。jar不包含tdk-c

  • 当我将此添加到我的项目父pom时: 项目运行失败如下: 当我删除依赖项时,项目将成功运行。 我只是想添加一个Eureka客户端到注册中心,但它不起作用。但是,当我使用Spring初始化器创建一个新项目时,它工作得很好。 每个答案都有帮助。 完整的项目如下:

  • 在尝试运行我的第一个HelloWorld应用程序时,我发现了以下异常: org.springframework.beans.factory.beanDefinitionStoreException:未能读取候选组件类嵌套异常为java.lang.IllegalStateException:由于找不到org/springframework/dao/dataAccessException,无法计算or

  • 我有一个应用程序,它使用注释来创建bean,而不是旧的基于XML的文件。 我需要使用一个使用基于XML的bean的库。我需要这些bean在我的应用程序中初始化并可用,否则我最终会重写相当多的代码。 我已经尝试使用@ComponentScan来查找它们,但正如预期的那样,由于类没有用@Component注释,因此无法找到它们。我尝试过使用@ImportResource,如这里所述,但没有成功。 所以