Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Bean method 'shardingSphereDataSource' must not be declared as autowired #34704

Open
LanaGan opened this issue Feb 18, 2025 · 2 comments
Open

Comments

@LanaGan
Copy link

LanaGan commented Feb 18, 2025

Question

In springboot(3.4.1) I rely on the shardingsphere-jdbc-core-spring-boot-starter package。The following error occurred
. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
' |
| .__|| ||| |_, | / / / /
=========|
|==============|/=////

:: Spring Boot :: (v3.4.1)

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-02-18T17:14:19.496+08:00 ERROR 23288 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @bean method 'shardingSphereDataSource' must not be declared as autowired; remove the method-level @Autowired annotation.
Offending resource: class path resource [org/apache/shardingsphere/spring/boot/ShardingSphereAutoConfiguration.class]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72) ~[spring-beans-6.2.1.jar:6.2.1]
at org.springframework.context.annotation.BeanMethod.validate(BeanMethod.java:52) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.context.annotation.ConfigurationClass.validate(ConfigurationClass.java:232) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.context.annotation.ConfigurationClassParser.validate(ConfigurationClassParser.java:214) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:419) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:290) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:349) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:118) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609) ~[spring-context-6.2.1.jar:6.2.1]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.4.1.jar:3.4.1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.4.1.jar:3.4.1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.4.1.jar:3.4.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.4.1.jar:3.4.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.4.1.jar:3.4.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.4.1.jar:3.4.1]
at com.ganlan.DemoApplication.main(DemoApplication.java:29) ~[classes/:na]

Disconnected from the target VM, address: '127.0.0.1:62888', transport: 'socket'

Process finished with exit code 1

@terrymanu
Copy link
Member

What is the version?

@wolf-hunter404
Copy link

What is the version?

I also encountered this error.
Spring boot version: 3.4.1
shardingsphere-jdbc-core-spring-boot-starter: 5.2.1

gradle dependencie:
implementation 'org.apache.shardingsphere:shardingsphere-jdbc-core-spring-boot-starter:5.2.1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants