ShardingSphere-JDBC
Scenarios
There are two ways you can configure Apache ShardingSphere: Java
and YAML
. Developers can choose the preferred method according to their requirements.
Limitations
Currently only Java language is supported.
Requirements
The development environment requires Java JRE 8 or later.
Procedure
- Rules configuration.
Please refer to User Manual for more details.
- Import Maven dependency
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>${latest.release.version}</version>
</dependency>
Notice: Please change
${latest.release.version}
to the actual version.
- Create YAML configuration file
# JDBC database name. In cluster mode, use this parameter to connect ShardingSphere-JDBC and ShardingSphere-Proxy.
# Default:logic_db
databaseName (?):
mode:
dataSources:
rules:
- !FOO_XXX
...
- !BAR_XXX
...
props:
key_1: value_1
key_2: value_2
- Take
spring boot
as an example, editapplication.properties
.
# Configuring DataSource Drivers
spring.datasource.driver-class-name=org.apache.shardingsphere.driver.ShardingSphereDriver
# Specify a YAML configuration file
spring.datasource.url=jdbc:shardingsphere:classpath:xxx.yaml
For details, see Spring Boot.
当前内容版权归 ShardingSphere 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ShardingSphere .