在“测试范围”中基于Maven启动Spring Boot Application

问题描述

我已经编写了一个Spring Boot应用程序,该应用程序应在开发过程中使用H2,并将mariadb用于集成测试和生产。为了进行开发,我在带有Java扩展的WSL2中使用Visual Studio Code。

在pom.xml中,我将H2存储库定义为依赖项:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.4.200</version>
    <scope>test</scope>
</dependency>

在VSCode中,我创建了3个启动配置“调试”,“调试(测试)”和“调试(产品)”。在launch.json文件中,我为不同的数据库配置定义了3个不同的spring配置文件。这是“测试”配置的示例:

{
    "type": "java","name": "Debug (test)","request": "launch","mainClass": "de.frickeldave.fleckerlteppich.telemetry.TelemetryApplication","preLaunchTask": "startmariadb","postDebugTask": "stopmariadb","args": "--spring.profiles.active=test"
} 

问题: 当我在VSCode中启动常规的“调试”配置时,我想使用H2数据库。但是由于定义<scope>test</test>,因此未加载依赖项,并且应用程序无法连接。当我删除“ test-scope”声明(这不是目标)时,它工作得很好。 我应该怎么做才能在测试范围内启动应用程序,以便在使用VSCode进行调试时可以使用H2?我可以添加一个起始参数吗?

预先感谢

关于戴夫

解决方法

范围test的依赖项在运行时不可用。

它们只能用于在构建过程中运行的测试。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...