Spring boot: No qualifying bean of ‘javax.sql.Datasource’ available: expected at least 1 bean which
时间: 2024-06-05 19:08:51 浏览: 477
This error occurs when Spring Boot is unable to find a bean that is required for your application to run. In this case, it is unable to find a bean for the `javax.sql.DataSource` class which is required for database operations.
To resolve this issue, you can try the following steps:
1. Check if you have added the necessary dependencies in your `pom.xml` file for the database you are using. For example, if you are using MySQL, you should have the `mysql-connector-java` dependency added.
2. Check if you have correctly configured the database properties in your `application.properties` file. Make sure the URL, username, and password are correct.
3. Check if you have annotated your database configuration class with `@Configuration` and `@EnableTransactionManagement`.
4. If you are using multiple databases, make sure you have annotated each `DataSource` bean with a unique name using `@Qualifier`.
5. If you are still facing the issue, try creating the `DataSource` bean manually in your configuration class using `@Bean` annotation.
I hope these steps help you resolve the issue.
阅读全文