Tistepin commented on issue #37845:
URL:
https://github.com/apache/shardingsphere/issues/37845#issuecomment-3802497136
Oracle version
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
The built-in version is
<version>19.3.0.0</version>
Druid Version
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.20</version>
</dependency>
Full master and slave Druid configs
新建文本文档 (2) is my application.properties
spring.datasource.druid.oracle 是 Master Database
spring.datasource.druid.oracle-read is slave Database
Inject using springboot's @ConfiguringProperties
The implementation involves manually switching data sources, with the
default data source being ShardingSphere JDBC
Data source implementation in “DataSourceConfig.java”
I just realized that as a @Bean, it will fail
Delete the @bean("ShardingSphereDataSource") and it will be successful
The reason may be that ShardingSphere connects to the Master database
during initialization, but for some reason it causes the connection to fail. As
long as I log out of PSCache, it will start successfully
The following uses Master Database as the default data source instead of
ShardingSphere Database to succeed
@Bean(name = "dynamicDataSource")
public DataSource dynamicDataSource(
) throws SQLException {
DynamicDataSource dynamicDataSource = new DynamicDataSource();
//默認數據源 为主从切换中间件返回的 dataSource
dynamicDataSource.setDefaultTargetDataSource(oracleDataSource());
//配置多數據源
Map<Object, Object> dataBaseMap = new HashMap<>(16);
// 从现在开始 DBTypeEnum.ORACLE.getValue() 代表是主从中间件
ShardingSphereDataSource
dataBaseMap.put(DBTypeEnum.ORACLE.getValue(), oracleDataSource());
dataBaseMap.put(DBTypeEnum.oracle_read.getValue(),
oracleReadDataSource());
dataBaseMap.put(DBTypeEnum.ORACLE_TEST.getValue(),
oracleTestDataSource());
dataBaseMap.put(DBTypeEnum.ORACLE_MAC3.getValue(),
oracleMac3DataSource());
dataBaseMap.put(DBTypeEnum.ORACLE_QMS_MAC1.getValue(),
oracleQmsMac1DataSource());
dynamicDataSource.setTargetDataSources(dataBaseMap);
return dynamicDataSource;
}
Startup error with ShardingSphere Database as default database
Error creating bean with name 'customizeAbstractSecurityInterceptor':
Unsatisfied dependency expressed through field 'securityMetadataSource'; nested
exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name
'customizeFilterInvocationSecurityMetadataSource': Unsatisfied dependency
expressed through field 'systemDao'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error
creating bean with name 'systemDao' defined in file
[F:\companyProject\後端\teaceOLD\tracewebapi\target\classes\com\mac1\traceapi\dao\TraceWeb\System\SystemDao.class]:
Unsatisfied dependency expressed through bean property 'sqlSessionFactory';
nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error
creating bean with name 'sqlSessionFactoryBean' defined in class path resource
[com/mac1/traceapi/util/MybatisConfig/DataSourceConfig.class]: Unsatisfied
dependency expressed through method 'sqlS
essionFactoryBean' parameter 1; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'ShardingSphereDataSource' defined in class path resource
[com/mac1/traceapi/util/MybatisConfig/DataSourceConfig.class]: Bean
instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[javax.sql.DataSource]: Factory method 'ShardingSphereDataSource' threw
exception; nested exception is java.sql.SQLRecoverableException: IO 错误: Socket
read timed out
As long as PSCache ShardingSphereDatabase is deleted, it will start
successfully
[DataSourceConfig.java](https://github.com/user-attachments/files/24870747/DataSourceConfig.java)
[新建文本文档 (2).txt](https://github.com/user-attachments/files/24870761/2.txt)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]