SpringBoot动态多数据源的配置

Springboot项目中用多套配置文件可以动态的切换数据源。事例如下


SpringBoot动态多数据源的配置
pom.xml的依赖为:

<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<project.profile>development</project.profile>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<project.profile>production</project.profile>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<project.profile>test</project.profile>
</properties>
</profile>
<profile>
<id>zztest</id>
<properties>
<project.profile>zztest</project.profile>
</properties>
</profile>
</profiles>
这样配置之后即可根据环境动态切换配置文件(包含数据源)