SpringCloud项目实现阿里云OSS服务,搭建项目测试的时候出现以下问题:
2020-05-28 15:15:24.071 INFO 1324 --- [ main] com.atguigu.oss.OssApplication : Starting OssApplication on LAPTOP-MNTNVTLB with PID 1324 (E:\IDEAProjects\guli_parent\service\service_oss\target\classes started by Joker in E:\IDEAProjects\guli_parent)
2020-05-28 15:15:24.073 INFO 1324 --- [ main] com.atguigu.oss.OssApplication : The following profiles are active: dev
2020-05-28 15:15:24.724 WARN 1324 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.atguigu.oss]' package. Please check your configuration.
2020-05-28 15:15:24.759 INFO 1324 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-05-28 15:15:24.761 INFO 1324 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2020-05-28 15:15:24.778 INFO 1324 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 3ms. Found 0 Redis repository interfaces.
2020-05-28 15:15:25.090 INFO 1324 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-05-28 15:15:25.764 INFO 1324 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8002 (http)
2020-05-28 15:15:25.776 INFO 1324 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-28 15:15:25.776 INFO 1324 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-05-28 15:15:25.864 INFO 1324 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-28 15:15:25.864 INFO 1324 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1746 ms
2020-05-28 15:15:26.148 INFO 1324 --- [ main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
2020-05-28 15:15:26.225 INFO 1324 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-28 15:15:26.299 WARN 1324 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-05-28 15:15:26.300 INFO 1324 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-05-28 15:15:26.305 INFO 1324 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-05-28 15:15:26.315 INFO 1324 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-05-28 15:15:26.316 ERROR 1324 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
根据描述Failed to determine a suitable driver class可知是因为缺少数据源配置
以下提供两种解决方案,可根据自己实际情况选择:
1.在配置文件中添加数据源相关配置
以yml为例,在配置文件中添加如下代码(在spring主key下)
datasource: #数据库配置
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8 #自己的url
username: root #自己的用户名和密码
password: 123456
较完整代码:
因为我的这个模块并不需要进行数据库相关操作,所以我采用了下面这种方式来解决问题
2.在启动类中添加如下代码
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
排除这个数据源自动配置类即可
较完整代码: