初始代码

This commit is contained in:
wangmingwei
2026-04-21 17:41:09 +08:00
parent 186ec6683a
commit b686ecac5f
493 changed files with 52349 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yunzhupaas-boot-common</artifactId>
<groupId>com.yunzhupaas</groupId>
<version>5.2.0-RELEASE</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yunzhupaas-common-shardingsphere</artifactId>
<dependencies>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-common-database</artifactId>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,46 @@
package com.yunzhupaas.config;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.sql.SQLException;
/**
* @author 云筑产品开发平台组
* @user N
* @copyright 深圳市乐程软件有限公司
* @date 2024/11/23 16:52
*/
@Configuration
@ConditionalOnMissingClass( "org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient")
@ConditionalOnProperty(prefix = "config", name = "sharding-sphere-enabled", havingValue = "true")
public class ShardingSphereAutoConfig {
public ShardingSphereAutoConfig() {
System.out.println("启用ShardingSphere");
}
public static final String PREFIX = "shardingsphere";
@Bean
public Object initShardingSphereDataSource(@Qualifier("dataSourceSystem") DynamicRoutingDataSource dataSource) throws SQLException, IOException, URISyntaxException {
// 加入ShardingSphere数据源
File file = new File(ShardingSphereAutoConfig.class.getClassLoader().getResource("sharding-sphere.yml").toURI());
DataSource SSDataSource = YamlShardingSphereDataSourceFactory.createDataSource(file);
dataSource.addDataSource(PREFIX, SSDataSource);
return null;
}
}