Failed to determine a suitable driver class问题解决

错误日志:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-20 23:00:50.664 ERROR 11184 --- [           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 classAction: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).Disconnected from the target VM, address: '127.0.0.1:53235', transport: 'socket'Process finished with exit code 1

日志中有这么一句:no profiles are currently active

说明没有配置profiles 也就是项目运行的代码环境,赶紧看一下yml配置:

spring:profiles:active: '@spring.active@'

我是这样写的,说明可能是’@spring.active@'没生效 那么我换成local试试

spring:profiles:#active: '@spring.active@'active: local

对我们的项目进行maven clean 然后再次运行:

Connected to the target VM, address: '127.0.0.1:53321', transport: 'socket'.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::        (v2.2.2.RELEASE)2019-12-20 23:07:27.055  INFO 10324 --- [           main] c.s.d.SelfDisciplineApplication          : Starting SelfDisciplineApplication on Suvue with PID 10324 (Z:\personal\code_repo\self-discipline\target\classes started by yj020 in Z:\personal\code_repo\self-discipline)
2019-12-20 23:07:27.060  INFO 10324 --- [           main] c.s.d.SelfDisciplineApplication          : The following profiles are active: local
2019-12-20 23:07:27.751  INFO 10324 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2019-12-20 23:07:27.754  INFO 10324 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2019-12-20 23:07:27.794  INFO 10324 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 24ms. Found 0 Redis repository interfaces.
2019-12-20 23:07:28.094  INFO 10324 --- [           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)
2019-12-20 23:07:28.340  INFO 10324 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 80 (http)
2019-12-20 23:07:28.349  INFO 10324 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-12-20 23:07:28.349  INFO 10324 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.29]
2019-12-20 23:07:28.444  INFO 10324 --- [           main] o.a.c.c.C.[.[localhost].[/discipline]    : Initializing Spring embedded WebApplicationContext
2019-12-20 23:07:28.445  INFO 10324 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1328 ms_ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ /               |         3.3.0 
2019-12-20 23:07:29.982  WARN 10324 --- [           main] c.b.m.core.metadata.TableInfoHelper      : Warn: Could not find @TableId in Class: cn.suvue.discipline.modular.entity.SetArtitleSort.
2019-12-20 23:07:30.010  WARN 10324 --- [           main] c.b.m.core.metadata.TableInfoHelper      : Warn: Could not find @TableId in Class: cn.suvue.discipline.modular.entity.Sorts.
2019-12-20 23:07:30.248  INFO 10324 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-20 23:07:30.586  INFO 10324 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 80 (http) with context path '/discipline'
2019-12-20 23:07:30.590  INFO 10324 --- [           main] c.s.d.SelfDisciplineApplication          : Started SelfDisciplineApplication in 4.139 seconds (JVM running for 5.441)

此时项目已经能正常运行了!大功告成

可是还是不甘心,没找到问题的根源。

在网上一番查找,结果发现自己的配置出了问题,下面附上正确配置方式:

pom.xml

<profiles><profile><id>devid><properties><spring.active>devspring.active>properties><activation><activeByDefault>trueactiveByDefault>activation>profile><profile><id>testid><properties><spring.active>testspring.active>properties>profile><profile><id>prodid><properties><spring.active>prodspring.active>properties>profile>
profiles><properties><resource.delimiter>@resource.delimiter>
properties>
<build><resources><resource><directory>src/main/resourcesdirectory><filtering>truefiltering>resource><resource><directory>src/main/resources.${spring.active}directory><filtering>falsefiltering>resource>resources>
build>

这时候在yml中我们就可以使用高级操作方式了!如下:

spring:profiles:active: @spring.active@


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部