在学习SpringBoot配置多数据源的时候,一直报错,连接数据库的配置文件问题
分为两种情况
spring-boot-starter-parent2.0.0之后不支持驼峰命名:
对于driverClassName不识别,修改为driver-class-name
将url修改为jdbc-url
spring-boot-starter-parent版本是2.0之前的
pom.xml文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<!-- 引入springboot依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 引入mybatis依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
</dependencies>
application.properties文件配置
spring.datasource.shang01.driverClassName =com.mysql.jdbc.Driver
spring.datasource.shang01.url=jdbc:mysql://localhost:3306/shang01?useUnicode=true&characterEncoding=utf-8
spring.datasource.shang01.username=root
spring.datasource.shang01.password=123456
spring.datasource.shang02.driverClassName =com.mysql.jdbc.Driver
spring.datasource.shang02.url=jdbc:mysql://localhost:3306/shang02?useUnicode=true&characterEncoding=utf-8
spring.datasource.shang02.username=root
spring.datasource.shang02.password=123456
spring-boot-starter-parent版本是2.0之后
pom.xml文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<!-- 引入springboot依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 引入mybatis依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
</dependencies>
application.properties文件配置
spring.datasource.test1.driver-class-name =com.mysql.jdbc.Driver
spring.datasource.test1.jdbc-url=jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=utf-8
spring.datasource.test1.username=root
spring.datasource.test1.password=123456
spring.datasource.test2.driver-class-name =com.mysql.jdbc.Driver
spring.datasource.test2.jdbc-url=jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=utf-8
spring.datasource.test2.username=root
spring.datasource.test2.password=123456