We would like to support two databases MySQL and Cassandra to our application. Our application will be built using Spring. I would to like to have common entities which has to be shared by both MySQL and Cassandra I would like to change the DB dynamically based on customer preference. How can I achieve this
我们想在我们的应用程序中支持两个MySQL和Cassandra数据库。我们的应用程序将使用Spring构建。我希望有一些必须由MySQL和Cassandra共享的通用实体我想根据客户的喜好动态更改数据库。我怎样才能做到这一点
1 个解决方案
#1
0
If your requirements to have the system runnable on both data stores, with only one at a time, this I think it is achievable.
如果您要求系统在两个数据存储上都可以运行,一次只能运行一个,我认为这是可以实现的。
The following advices i believe will let you achieve this but i didn't try'em: (supposing that you uses spring-boot)
以下建议我相信会让你实现这一点,但我没有尝试:(假设你使用spring-boot)
- In maven put the dependency for spring data jpa and spring data mongo.
- 在maven中为spring数据jpa和spring数据mongo设置了依赖关系。
- Enable both jpa and mongo repositories (see EnableJpaRepositoies)
- 启用jpa和mongo存储库(请参阅EnableJpaRepositoies)
- On entities put both JPA and Mongo annotations.
- 在实体上放置JPA和Mongo注释。
- Use PagingAndSortingRepository as base interface for you repositories
- 使用PagingAndSortingRepository作为存储库的基本接口
- In application.properties either configure mysql or mongo db through spring boot well-defined properties
- 在application.properties中,通过spring boot明确定义的属性配置mysql或mongo db
This might work in regular spring apps but will need modifications; also include corresponding driver dependencies in pom file.
这可能适用于常规弹簧应用程序,但需要修改;还包括pom文件中的相应驱动程序依赖项。
Edit: you can use 'spring.data.jpa.repositories.enabled=false' ( and its mongo counterpart) source: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfiguration.java
编辑:您可以使用'spring.data.jpa.repositories.enabled = false'(及其mongo对应的)源代码:https://github.com/spring-projects/spring-boot/blob/master/spring-boot-自动配置/ src目录/主/ JAVA /组织/ springframework的的/ boot /自动配置/数据/ JPA / JpaRepositoriesAutoConfiguration.java
#1
0
If your requirements to have the system runnable on both data stores, with only one at a time, this I think it is achievable.
如果您要求系统在两个数据存储上都可以运行,一次只能运行一个,我认为这是可以实现的。
The following advices i believe will let you achieve this but i didn't try'em: (supposing that you uses spring-boot)
以下建议我相信会让你实现这一点,但我没有尝试:(假设你使用spring-boot)
- In maven put the dependency for spring data jpa and spring data mongo.
- 在maven中为spring数据jpa和spring数据mongo设置了依赖关系。
- Enable both jpa and mongo repositories (see EnableJpaRepositoies)
- 启用jpa和mongo存储库(请参阅EnableJpaRepositoies)
- On entities put both JPA and Mongo annotations.
- 在实体上放置JPA和Mongo注释。
- Use PagingAndSortingRepository as base interface for you repositories
- 使用PagingAndSortingRepository作为存储库的基本接口
- In application.properties either configure mysql or mongo db through spring boot well-defined properties
- 在application.properties中,通过spring boot明确定义的属性配置mysql或mongo db
This might work in regular spring apps but will need modifications; also include corresponding driver dependencies in pom file.
这可能适用于常规弹簧应用程序,但需要修改;还包括pom文件中的相应驱动程序依赖项。
Edit: you can use 'spring.data.jpa.repositories.enabled=false' ( and its mongo counterpart) source: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfiguration.java
编辑:您可以使用'spring.data.jpa.repositories.enabled = false'(及其mongo对应的)源代码:https://github.com/spring-projects/spring-boot/blob/master/spring-boot-自动配置/ src目录/主/ JAVA /组织/ springframework的的/ boot /自动配置/数据/ JPA / JpaRepositoriesAutoConfiguration.java