Skip to content

Commit

Permalink
fix: 分库分表功能失效
Browse files Browse the repository at this point in the history
shardingsphere-jdbc-core-spring-boot-starter 依赖版本过低
  • Loading branch information
201206030 committed Dec 21, 2023
1 parent 2270072 commit 7b4b975
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<elasticsearch.version>8.2.0</elasticsearch.version>
<xxl-job.version>2.3.1</xxl-job.version>
<sentinel.version>1.8.4</sentinel.version>
<shardingsphere-jdbc.version>5.1.1</shardingsphere-jdbc.version>
<shardingsphere-jdbc.version>5.2.1</shardingsphere-jdbc.version>
<redisson.version>3.19.1</redisson.version>
<spring-boot-admin.version>3.0.0-M1</spring-boot-admin.version>
<springdoc-openapi.version>2.0.0</springdoc-openapi.version>
Expand Down Expand Up @@ -149,6 +149,11 @@
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>${shardingsphere-jdbc.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Spring Boot 管理和监控 -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.xxyopen.novel.core.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

/**
* ShardingSphere 配置类,控制是否开启 ShardingSphere
*
* @author xiongxiaoyang
* @date 2023/12/21
*/
@Configuration
@EnableAutoConfiguration(exclude = {
org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration.class
})
@ConditionalOnProperty(
prefix = "spring.shardingsphere",
name = {"enabled"},
havingValue = "false"
)
public class ShardingSphereConfiguration {

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"name": "spring.elasticsearch.ssl.verification-mode",
"type": "java.lang.String",
"description": "设置 ssl 的认证模式,如果该配置项为 none ,说明不需要认证,信任所有的 ssl 证书."
},
{
"defaultValue": true,
"name": "spring.shardingsphere.enabled",
"description": "Whether enable shardingsphere or not.",
"type": "java.lang.Boolean"
}
]
}
15 changes: 8 additions & 7 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ spring:
mode:
# 单机模式
type: Standalone
# 元数据持久化
repository:
# 文件持久化
type: File
# 数据库持久化
type: JDBC
props:
# 元数据存储路径
path: .shardingsphere
# 使用本地配置覆盖持久化配置
overwrite: true
# 元数据存储类型
provider: H2
jdbc_url: jdbc:h2:./.h2/shardingsphere

# 数据源配置
datasource:
names: ds_0
Expand Down Expand Up @@ -87,7 +88,7 @@ spring:
redis:
host: 127.0.0.1
port: 6379
password: 123456
password: test123456

# Elasticsearch 配置
elasticsearch:
Expand Down

0 comments on commit 7b4b975

Please sign in to comment.