![](/img/trans.png)
[英]Spring Boot application, running on WAS 9, eventually fails to connect to DB2 database
[英]There is other option to connect spring boot to db2?
我正在使用 Spring boot,我需要使用 db2 數據庫連接,目前配置為使用 maven 和屬性,但首先我需要創建 jks 文件,並且測試部分不起作用,因為該文件不是那里。
這是我的連接屬性 jdbc:db2://examplecon:80207/basejl:sslConnection=true;sslTrustStoreLocation=folder/file.jks;
在 spring 完成設置后,如何將 spring boot 與 db2 連接起來?
您可以在啟動上下文之前開始生成文件:
@SpringBootApplication
public class App {
public static void main(String[] args) {
generateFile("folder/file.jks");
SpringApplication.run(App.class, args);
}
private static void generateFile(String s) {
// TODO: generate file.jks here
}
}
在這種情況下,您可以使用 spring 提供的常用數據庫連接方式。
像這個例子: https ://www.sourcecodeexamples.net/2021/08/spring-boot-db2-connection-example.html
出於測試目的,您可以將測試配置與事件偵聽器一起使用。 它將在 Context 啟動之前運行:
@SpringBootTest
@TestPropertySource(locations="classpath:test.properties")
class TestConfigurationExampleAppTests {
@EventListener(ApplicationStartingEvent.class)
public void generateFile() {
// TODO: generate file.jks here
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.