apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.87k stars 6.73k forks source link

If spring.shardingsphere.rules is not configured, ShardingSphereDataSource cannot be injected #13554

Closed Astierred closed 2 years ago

Astierred commented 2 years ago

Which version of ShardingSphere did you use?

5.0.0

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected & Actual behavior

image

Reason analyze

I did not configure the properties of "spring.shardingsphere.rules" Because I only need to use the distributed transaction of ShardingSphere image In version 5.0.0-beta, the above configuration can successfully start the application But in version 5.0.0, the return result of the method getMatchOutcome in the class LocalRulesCondition is noMatch An exception will be thrown during startup Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.shardingsphere.infra.config.mode.ModeConfiguration' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} If I configure the parameters spring.shardingsphere.mode.type= Memory The seata service will throw an exception again Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.shardingsphere.infra.metadata.resource.CachedDatabaseMetaData.getUrl()" because "this.cachedDatabaseMetaData" is null When I configure the "spring.shardingsphere.rules" parameters to successfully start the application

zhaojinchao95 commented 2 years ago

@SFlora Hi, sharding-jdbc are must be config with rule. If you needn't rule, you can try sharding-proxy.

makexiao113 commented 2 years ago

i have same problem

ASCE1885 commented 2 years ago

the same version 5.0.0, I have config with rule, but still got No qualifying bean of type 'org.apache.shardingsphere.infra.config.mode.ModeConfiguration' available

zhaojinchao95 commented 2 years ago

the same version 5.0.0, I have config with rule, but still got No qualifying bean of type 'org.apache.shardingsphere.infra.config.mode.ModeConfiguration' available

Can you provider your configuration?

zhaojinchao95 commented 2 years ago

i have same problem

Can you provider your configuration?

makexiao113 commented 2 years ago

i have same problem

Can you provider your configuration?

spring: application: name: membership shardingsphere: datasource: names: master master: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/membership username: membership password: membership mode: type: Memory schema: name: master

makexiao113 commented 2 years ago

i have same problem

Can you provider your configuration?

this is my issue:https://github.com/apache/shardingsphere/issues/13526

Astierred commented 2 years ago

@SFlora Hi, sharding-jdbc are must be config with rule. If you needn't rule, you can try sharding-proxy.

But I can run successfully in version 5.0.0-beta without config "rules" Is "must be config with rule" a new requirement of the new version?

ASCE1885 commented 2 years ago

i have same problem

Can you provider your configuration?

I am using Spring Boot 2.1.1.RELEASE, pom.xml:

<dependency>
  <groupId>org.apache.shardingsphere</groupId>
  <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
  <version>5.0.0</version>
</dependency>

application.properties:

spring.shardingsphere.datasource.names = master1

spring.shardingsphere.datasource.master1.jdbc-url = jdbc:mysql://30.99.88.33:3306/xxx
spring.shardingsphere.datasource.master1.type =  com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.master1.driver-class-name = com.mysql.jdbc.Driver
spring.shardingsphere.datasource.master1.username = asce
spring.shardingsphere.datasource.master1.password = xxx
spring.shardingsphere.datasource.master1.xxx =  # 数据库连接池的其它属性

spring.shardingsphere.rules.encrypt.tables.t_user_a.columns.email.cipher-column=email
spring.shardingsphere.rules.encrypt.tables.t_user_a.columns.email.encryptor-name=encryptor_aes

spring.shardingsphere.rules.encrypt.encryptors.encryptor_aes.type = AES
spring.shardingsphere.rules.encrypt.encryptors.encryptor_aes.props.aes-key-value = xxxx

spring.shardingsphere.rules.encrypt.queryWithCipherColumn = true
spring.shardingsphere.props.sql.show = true
makexiao113 commented 2 years ago

the same version 5.0.0, I have config with rule, but still got No qualifying bean of type 'org.apache.shardingsphere.infra.config.mode.ModeConfiguration' available

you can add this configuration: spring.shardingshpere.mode.type=Memory

https://shardingsphere.apache.org/document/5.0.0/cn/user-manual/shardingsphere-jdbc/configuration/yaml/mode/

zhaojinchao95 commented 2 years ago

@ASCE1885 Hi bro, Can you change encryptor_aes to encryptor-aes. Then try it again.

zhaojinchao95 commented 2 years ago

@SFlora Hi, sharding-jdbc are must be config with rule. If you needn't rule, you can try sharding-proxy.

But I can run successfully in version 5.0.0-beta without config "rules" Is "must be config with rule" a new requirement of the new version?

yes, i think if you use sharding-jdbc, you hava sharding demand. Do you have other ideas?

zhaojinchao95 commented 2 years ago

spring.shardingshpere.mode.type=Memory

There are optional. So you can not set it

ASCE1885 commented 2 years ago

@ASCE1885 Hi bro, Can you change encryptor_aes to encryptor-aes. Then try it again.

after changing encryptor_aes to encryptor-aes the result is still the same. But I made some changes:

1) update spring boot to 2.3.4.RELEASE
2) add `spring.shardingshpere.mode.type=Memory` like @zjcnb  say

now the project can launch successfully, but when I run a select SQL through MyBatis, there is a NoSuchElementException:null.

image

zhaojinchao95 commented 2 years ago

add spring.shardingshpere.mode.type=Memory like @zjcnb say

You needn't configuration mode Memory, And now the project can launch successfully, but when I run a select SQL through MyBatis, there is a NoSuchElementException:null. it 's a new problem, Can you create new issue?

legendyman commented 2 years ago

this is my configuration, image in this configuration, i have excluded druid data source configuration in springboot runner class. the issue is : image thank you