Liberty + Spring Data 中的容器管理的 MongoDB 连接

2024-01-08

我们开发了一个应用程序Spring Boot + spring data(后端)+MongoDB并使用IBM Websphere Liberty作为应用服务器。我们被利用了“应用程序管理的数据库连接” in an yml文件并享受 Spring Boot 的好处autoconfiguration.

由于政策变化,我们需要管理 Liberty Server 中的数据库连接(使用 mongo 功能),Server.xml。我花了一整天的时间寻找一个很好的例子来做到这一点,但在 Spring 中没有找到任何例子“容器管理的 MongoDB 连接” in IBM Websphere Liberty Server.

有人可以在这里支持吗?


查看这是另一个 stackoverflow 解决方案 https://stackoverflow.com/questions/17822106/setting-up-a-datasource-with-websphere-liberty-profile-8-5。以下是如何在 Spring Boot 应用程序中使用它的扩展。

您应该能够以相同的方式注入数据源。您甚至可以将其注入到您的配置中并将其包装在 Spring 中DelegatingDataSource.

@Configuration
public class DataSourceConfiguration {

    // This is the last code section from that link above
    @Resource(lookup = "jdbc/oracle")
    DataSource ds;

    @Bean
    public DataSource mySpringManagedDS() {
        return new DelegatingDataSource(ds);
    }

}

然后你应该能够注入mySpringManagedDS DataSource进入你的Component, Service, etc.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Liberty + Spring Data 中的容器管理的 MongoDB 连接 的相关文章

随机推荐