【发布时间】:2020-10-06 14:30:23
【问题描述】:
我编写了一个 Spring Boot 应用程序,它应该在开发过程中使用 H2,并在集成测试和生产过程中使用 mariadb。对于开发,我在 WSL2 中使用带有 Java 扩展的 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> 没有加载依赖项并且应用程序无法连接。当我删除“测试范围”声明(这不是目标)时,它工作得很好。
我该怎么做才能在测试范围内启动应用程序,以便在使用 VSCode 进行调试时使用 H2?有没有我可以添加的起始参数?
提前致谢
问候戴夫
【问题讨论】:
标签: spring-boot maven visual-studio-code vscode-debugger vscode-tasks