还有其他选择可以将弹簧靴连接到DB2吗?

发布于 2025-02-06 04:46:10 字数 241 浏览 2 评论 0 原文

我正在使用Spring Boot,我需要使用DB2数据库连接,目前已配置为使用Maven和属性,但是首先我需要创建JKS文件,并且测试零件不起作用,因为此文件不是那里。

这是我的连接属性 JDBC:db2:// exipplecon:80207/basejl:sslConnection = true; sslTrustStorElocation = folder/file.jks;

在那个春季完成后,如何将弹簧靴与DB2连接到所有设置?

I'm working with Spring boot, and I need to use a db2 database connection, currently is configured to work with maven and properties, but first I need to create the jks file, and testing part doesn't works because this file is not there.

this is my connection property
jdbc:db2://examplecon:80207/basejl:sslConnection=true;sslTrustStoreLocation=folder/file.jks;

How can I connect spring boot with db2 after that spring finish to set all?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七堇年 2025-02-13 04:46:10

您可以在启动上下文之前开始生成文件:

@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提供的DB连接的通常方式。

像这个示例:

为了进行测试目的,您可以将测试配置与事件侦听器一起使用。它将在上下文开始之前运行:

@SpringBootTest
@TestPropertySource(locations="classpath:test.properties")
class TestConfigurationExampleAppTests {

  @EventListener(ApplicationStartingEvent.class)
  public void generateFile() {
    // TODO: generate file.jks here
  }
}

You can start generating the file before the context is been started:

@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
  }

}

In this case you can use the usual way of db connection that is provided by spring.

Like this example:
https://www.sourcecodeexamples.net/2021/08/spring-boot-db2-connection-example.html

For testing purpose, you can use Test Configuration with Event Listener. It will run before Context will start:

@SpringBootTest
@TestPropertySource(locations="classpath:test.properties")
class TestConfigurationExampleAppTests {

  @EventListener(ApplicationStartingEvent.class)
  public void generateFile() {
    // TODO: generate file.jks here
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文