Reputation: 11
How to build a Spring Boot application
which can switch between JPA
and MongoDB
with only configuration changes?
Upvotes: 1
Views: 124
Reputation: 99
Well both JPA and MongoDB config are basically beans, in case of JPA it's some kind of DataSource() bean and incase of MongoDB, it's the MongoTemplate() bean. But, if you are configuring the beans using application.yaml
with built in properties like spring.data spring.data.xxx
or spring.mongo.xxx
If I understood correctly what you meant by
configuration changes
then you are meaning feature toogle. In that case there are a number of ways to achieve that in Spring. @ConditionalOnPropety, @ConditionaOnMissingBean, Spring profiling - @ActiveProfile etc.
It basically depends on your particulary use case. Aditionally you can make disable any bean injection like as follows:
(@Autowired(required=false))
That way, any bean injection can be avoided.
Upvotes: 1