springboot项目中Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded的问题解决

springboot项目中Failed to configure a DataSource: 'url' attribute is not specified and no embedded的问题解决

问题描述

启动spring boot项目时,在控制台出现以下错误,并且服务终止。

D:\Java\jdk1.8.0_144\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2020.3\lib\idea_rt.jar=1380:D:\Program Files\JetBrains\IntelliJ IDEA 2020.3\bin" -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath D:\Java\jdk1.8.0_144\jre\lib\charsets.jar;D:\Java\jdk1.8.0_144\jre\lib\deploy.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\access-bridge-64.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\cldrdata.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\dnsns.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\jaccess.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\localedata.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\nashorn.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\sunec.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar;D:\Java\jdk1.8.0_144\jre\lib\ext\zipfs.jar;D:\Java\jdk1.8.0_144\jre\lib\javaws.jar;D:\Java\jdk1.8.0_144\jre\lib\jce.jar;D:\Java\jdk1.8.0_144\jre\lib\jfr.jar;D:\Java\jdk1.8.0_144\jre\lib\jfxswt.jar;D:\Java\jdk1.8.0_144\jre\lib\jsse.jar;D:\Java\jdk1.8.0_144\jre\lib\management-agent.jar;D:\Java\jdk1.8.0_144\jre\lib\plugin.jar;D:\Java\jdk1.8.0_144\jre\lib\resources.jar;D:\Java\jdk1.8.0_144\jre\lib\rt.jar;E:\devhuaweicloud\fengshen-yayan-service\target\classes;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.2.7.RELEASE\spring-boot-starter-web-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-starter\2.2.7.RELEASE\spring-boot-starter-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot\2.2.7.RELEASE\spring-boot-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.2.7.RELEASE\spring-boot-starter-logging-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\zheng\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\zheng\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;C:\Users\zheng\.m2\repository\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;C:\Users\zheng\.m2\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;C:\Users\zheng\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\zheng\.m2\repository\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.2.7.RELEASE\spring-boot-starter-json-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.10.4\jackson-databind-2.10.4.jar;C:\Users\zheng\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.10.4\jackson-core-2.10.4.jar;C:\Users\zheng\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.4\jackson-datatype-jdk8-2.10.4.jar;C:\Users\zheng\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.4\jackson-datatype-jsr310-2.10.4.jar;C:\Users\zheng\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.4\jackson-module-parameter-names-2.10.4.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.2.7.RELEASE\spring-boot-starter-tomcat-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.34\tomcat-embed-core-9.0.34.jar;C:\Users\zheng\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.34\tomcat-embed-el-9.0.34.jar;C:\Users\zheng\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.34\tomcat-embed-websocket-9.0.34.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-starter-validation\2.2.7.RELEASE\spring-boot-starter-validation-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;C:\Users\zheng\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.19.Final\hibernate-validator-6.0.19.Final.jar;C:\Users\zheng\.m2\repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-web\5.2.6.RELEASE\spring-web-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-webmvc\5.2.6.RELEASE\spring-webmvc-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-aop\5.2.6.RELEASE\spring-aop-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-context\5.2.6.RELEASE\spring-context-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-expression\5.2.6.RELEASE\spring-expression-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar;C:\Users\zheng\.m2\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;C:\Users\zheng\.m2\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;C:\Users\zheng\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\zheng\.m2\repository\net\bytebuddy\byte-buddy\1.10.10\byte-buddy-1.10.10.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-core\5.2.6.RELEASE\spring-core-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-jcl\5.2.6.RELEASE\spring-jcl-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\zheng\.m2\repository\commons-fileupload\commons-fileupload\1.3.1\commons-fileupload-1.3.1.jar;C:\Users\zheng\.m2\repository\commons-collections\commons-collections\3.2\commons-collections-3.2.jar;C:\Users\zheng\.m2\repository\commons-beanutils\commons-beanutils\1.9.2\commons-beanutils-1.9.2.jar;C:\Users\zheng\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;C:\Users\zheng\.m2\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;C:\Users\zheng\.m2\repository\org\apache\commons\commons-lang3\3.6\commons-lang3-3.6.jar;C:\Users\zheng\.m2\repository\com\google\guava\guava\23.0\guava-23.0.jar;C:\Users\zheng\.m2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;C:\Users\zheng\.m2\repository\com\google\errorprone\error_prone_annotations\2.0.18\error_prone_annotations-2.0.18.jar;C:\Users\zheng\.m2\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar;C:\Users\zheng\.m2\repository\org\codehaus\mojo\animal-sniffer-annotations\1.14\animal-sniffer-annotations-1.14.jar;C:\Users\zheng\.m2\repository\com\alibaba\druid\1.0.25\druid-1.0.25.jar;D:\Java\jdk1.8.0_144\lib\jconsole.jar;D:\Java\jdk1.8.0_144\lib\tools.jar;C:\Users\zheng\.m2\repository\mysql\mysql-connector-java\8.0.20\mysql-connector-java-8.0.20.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-jdbc\5.2.2.RELEASE\spring-jdbc-5.2.2.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-beans\5.2.6.RELEASE\spring-beans-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-tx\5.2.6.RELEASE\spring-tx-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\com\baomidou\mybatis-plus\3.1.1\mybatis-plus-3.1.1.jar;C:\Users\zheng\.m2\repository\com\baomidou\mybatis-plus-extension\3.1.1\mybatis-plus-extension-3.1.1.jar;C:\Users\zheng\.m2\repository\com\baomidou\mybatis-plus-core\3.1.1\mybatis-plus-core-3.1.1.jar;C:\Users\zheng\.m2\repository\com\baomidou\mybatis-plus-annotation\3.1.1\mybatis-plus-annotation-3.1.1.jar;C:\Users\zheng\.m2\repository\com\github\jsqlparser\jsqlparser\1.2\jsqlparser-1.2.jar;C:\Users\zheng\.m2\repository\org\mybatis\mybatis\3.5.1\mybatis-3.5.1.jar;C:\Users\zheng\.m2\repository\org\mybatis\mybatis-spring\2.0.1\mybatis-spring-2.0.1.jar;C:\Users\zheng\.m2\repository\com\baomidou\mybatis-plus-generator\3.1.1\mybatis-plus-generator-3.1.1.jar;C:\Users\zheng\.m2\repository\com\baomidou\mybatis-plus-boot-starter\3.1.0\mybatis-plus-boot-starter-3.1.0.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.2.7.RELEASE\spring-boot-autoconfigure-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.2.7.RELEASE\spring-boot-starter-jdbc-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\com\zaxxer\HikariCP\3.4.3\HikariCP-3.4.3.jar;C:\Users\zheng\.m2\repository\org\springframework\org.springframework.transaction\3.2.2.RELEASE\org.springframework.transaction-3.2.2.RELEASE.jar;C:\Users\zheng\.m2\repository\org\aopalliance\com.springsource.org.aopalliance\1.0.0\com.springsource.org.aopalliance-1.0.0.jar;C:\Users\zheng\.m2\repository\org\springframework\org.springframework.beans\3.2.2.RELEASE\org.springframework.beans-3.2.2.RELEASE.jar;C:\Users\zheng\.m2\repository\org\apache\commons\com.springsource.org.apache.commons.logging\1.1.1\com.springsource.org.apache.commons.logging-1.1.1.jar;C:\Users\zheng\.m2\repository\org\springframework\org.springframework.context\3.2.2.RELEASE\org.springframework.context-3.2.2.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\org.springframework.aop\3.2.2.RELEASE\org.springframework.aop-3.2.2.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\org.springframework.core\3.2.2.RELEASE\org.springframework.core-3.2.2.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\boot\spring-boot-starter-data-redis\2.1.3.RELEASE\spring-boot-starter-data-redis-2.1.3.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\data\spring-data-redis\2.2.7.RELEASE\spring-data-redis-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\data\spring-data-keyvalue\2.2.7.RELEASE\spring-data-keyvalue-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\data\spring-data-commons\2.2.7.RELEASE\spring-data-commons-2.2.7.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-oxm\5.2.6.RELEASE\spring-oxm-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\spring-context-support\5.2.6.RELEASE\spring-context-support-5.2.6.RELEASE.jar;C:\Users\zheng\.m2\repository\io\lettuce\lettuce-core\5.2.2.RELEASE\lettuce-core-5.2.2.RELEASE.jar;C:\Users\zheng\.m2\repository\io\netty\netty-common\4.1.49.Final\netty-common-4.1.49.Final.jar;C:\Users\zheng\.m2\repository\io\netty\netty-handler\4.1.49.Final\netty-handler-4.1.49.Final.jar;C:\Users\zheng\.m2\repository\io\netty\netty-resolver\4.1.49.Final\netty-resolver-4.1.49.Final.jar;C:\Users\zheng\.m2\repository\io\netty\netty-buffer\4.1.49.Final\netty-buffer-4.1.49.Final.jar;C:\Users\zheng\.m2\repository\io\netty\netty-codec\4.1.49.Final\netty-codec-4.1.49.Final.jar;C:\Users\zheng\.m2\repository\io\netty\netty-transport\4.1.49.Final\netty-transport-4.1.49.Final.jar;C:\Users\zheng\.m2\repository\io\projectreactor\reactor-core\3.3.5.RELEASE\reactor-core-3.3.5.RELEASE.jar;C:\Users\zheng\.m2\repository\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;C:\Users\zheng\.m2\repository\redis\clients\jedis\2.9.1\jedis-2.9.1.jar;C:\Users\zheng\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;C:\Users\zheng\.m2\repository\org\apache\commons\commons-pool2\2.7.0\commons-pool2-2.7.0.jar;C:\Users\zheng\.m2\repository\io\springfox\springfox-swagger2\2.8.0\springfox-swagger2-2.8.0.jar;C:\Users\zheng\.m2\repository\io\swagger\swagger-annotations\1.5.14\swagger-annotations-1.5.14.jar;C:\Users\zheng\.m2\repository\io\swagger\swagger-models\1.5.14\swagger-models-1.5.14.jar;C:\Users\zheng\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.4\jackson-annotations-2.10.4.jar;C:\Users\zheng\.m2\repository\io\springfox\springfox-spi\2.8.0\springfox-spi-2.8.0.jar;C:\Users\zheng\.m2\repository\io\springfox\springfox-core\2.8.0\springfox-core-2.8.0.jar;C:\Users\zheng\.m2\repository\io\springfox\springfox-schema\2.8.0\springfox-schema-2.8.0.jar;C:\Users\zheng\.m2\repository\io\springfox\springfox-swagger-common\2.8.0\springfox-swagger-common-2.8.0.jar;C:\Users\zheng\.m2\repository\io\springfox\springfox-spring-web\2.8.0\springfox-spring-web-2.8.0.jar;C:\Users\zheng\.m2\repository\org\reflections\reflections\0.9.11\reflections-0.9.11.jar;C:\Users\zheng\.m2\repository\org\javassist\javassist\3.21.0-GA\javassist-3.21.0-GA.jar;C:\Users\zheng\.m2\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;C:\Users\zheng\.m2\repository\org\springframework\plugin\spring-plugin-core\1.2.0.RELEASE\spring-plugin-core-1.2.0.RELEASE.jar;C:\Users\zheng\.m2\repository\org\springframework\plugin\spring-plugin-metadata\1.2.0.RELEASE\spring-plugin-metadata-1.2.0.RELEASE.jar;C:\Users\zheng\.m2\repository\org\mapstruct\mapstruct\1.2.0.Final\mapstruct-1.2.0.Final.jar;C:\Users\zheng\.m2\repository\io\springfox\springfox-swagger-ui\2.8.0\springfox-swagger-ui-2.8.0.jar;C:\Users\zheng\.m2\repository\com\microsoft\sqlserver\mssql-jdbc\6.1.0.jre8\mssql-jdbc-6.1.0.jre8.jar;C:\Users\zheng\.m2\repository\com\microsoft\azure\azure-keyvault\0.9.3\azure-keyvault-0.9.3.jar;C:\Users\zheng\.m2\repository\com\microsoft\azure\azure-core\0.9.3\azure-core-0.9.3.jar;C:\Users\zheng\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\zheng\.m2\repository\javax\mail\mail\1.4.5\mail-1.4.5.jar;C:\Users\zheng\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\zheng\.m2\repository\com\sun\jersey\jersey-client\1.13\jersey-client-1.13.jar;C:\Users\zheng\.m2\repository\com\sun\jersey\jersey-core\1.13\jersey-core-1.13.jar;C:\Users\zheng\.m2\repository\com\sun\jersey\jersey-json\1.13\jersey-json-1.13.jar;C:\Users\zheng\.m2\repository\org\codehaus\jettison\jettison\1.1\jettison-1.1.jar;C:\Users\zheng\.m2\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar;C:\Users\zheng\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb-impl-2.2.3-1.jar;C:\Users\zheng\.m2\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\zheng\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;C:\Users\zheng\.m2\repository\org\codehaus\jackson\jackson-core-asl\1.9.2\jackson-core-asl-1.9.2.jar;C:\Users\zheng\.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.9.2\jackson-mapper-asl-1.9.2.jar;C:\Users\zheng\.m2\repository\org\codehaus\jackson\jackson-jaxrs\1.9.2\jackson-jaxrs-1.9.2.jar;C:\Users\zheng\.m2\repository\org\codehaus\jackson\jackson-xc\1.9.2\jackson-xc-1.9.2.jar;C:\Users\zheng\.m2\repository\org\apache\httpcomponents\httpclient\4.5.12\httpclient-4.5.12.jar;C:\Users\zheng\.m2\repository\org\apache\httpcomponents\httpcore\4.4.13\httpcore-4.4.13.jar;C:\Users\zheng\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;C:\Users\zheng\.m2\repository\com\microsoft\azure\adal4j\1.0.0\adal4j-1.0.0.jar;C:\Users\zheng\.m2\repository\com\nimbusds\oauth2-oidc-sdk\4.5\oauth2-oidc-sdk-4.5.jar;C:\Users\zheng\.m2\repository\net\jcip\jcip-annotations\1.0\jcip-annotations-1.0.jar;C:\Users\zheng\.m2\repository\com\nimbusds\lang-tag\1.4\lang-tag-1.4.jar;C:\Users\zheng\.m2\repository\com\nimbusds\nimbus-jose-jwt\3.1.2\nimbus-jose-jwt-3.1.2.jar;C:\Users\zheng\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.51\bcprov-jdk15on-1.51.jar;C:\Users\zheng\.m2\repository\com\google\code\gson\gson\2.8.6\gson-2.8.6.jar;C:\Users\zheng\.m2\repository\net\sourceforge\jtds\jtds\1.3.1\jtds-1.3.1.jar com.wongoing.FengshenApplication

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.7.RELEASE)

2021-01-12 13:17:14.789  INFO 512 --- [           main] com.wongoing.FengshenApplication         : Starting FengshenApplication on zhenglibing-pc with PID 512 (E:\devhuaweicloud\fengshen-yayan-service\target\classes started by zheng in E:\devhuaweicloud\fengshen-yayan-service)
2021-01-12 13:17:14.794  INFO 512 --- [           main] com.wongoing.FengshenApplication         : No active profile set, falling back to default profiles: default
2021-01-12 13:17:15.736  INFO 512 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-01-12 13:17:15.738  INFO 512 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-01-12 13:17:15.764  INFO 512 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 11ms. Found 0 Redis repository interfaces.
2021-01-12 13:17:16.015  INFO 512 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'redisConfig' of type [com.wongoing.redis.RedisConfig$$EnhancerBySpringCGLIB$$e9bb973f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-01-12 13:17:16.310  INFO 512 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-01-12 13:17:16.320  INFO 512 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-01-12 13:17:16.320  INFO 512 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.34]
2021-01-12 13:17:16.454  INFO 512 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-01-12 13:17:16.454  INFO 512 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1612 ms
2021-01-12 13:17:16.529  WARN 512 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tbPpRfidstockController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tbPpRfidstockMapper' defined in file [E:\devhuaweicloud\fengshen-yayan-service\target\classes\com\wongoing\sys\mapper\TbPpRfidstockMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is 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
2021-01-12 13:17:16.532  INFO 512 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-01-12 13:17:16.562  INFO 512 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-01-12 13:17:16.568 ERROR 512 --- [           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


错误截图如下:
在这里插入图片描述

错误原因

通过查阅资料及分析,发现是因为在pom.xml中引入了jdbc的依赖包,如下:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.2.2.RELEASE</version>
</dependency>

但是却没有在spring配置文件中配置数据源的相关信息导致,如下

spring.datasource.driver-class-name =
spring.datasource.url =
spring.datasource.username =
spring.datasource.password =

解决方法

1、第一种方法,也是最简单的方法,如果你的springboot项目不是通spring.jdbc访问数据库,则在pom.xml文件中把spring.jdbc的依赖删除或注释就行,就是把下面的信息在pom.xml中删除注释。

<!--
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.2.2.RELEASE</version>
</dependency>
-->

2、第二种方法,就是在application.properties或者application.yml中增加数据源的配置,如下:
application.properties

spring.datasource.driver-class-name =
spring.datasource.url = jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username = root
spring.datasource.password = ******

3、第三种方法,就是在SpringBoot启动类中排除jdbc的自动装配机制即可(如果使用了其他的数据库连接池,比如Druid,则可能会出现问题,不建议使用)

@SpringBootApplication(exclude=DataSourceAutoConfiguration.class)

代码如下:

package com.wongoing;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude= DataSourceAutoConfiguration.class)
public class FengshenApplication {

    public static void main(String[] args) {
        SpringApplication.run(FengshenApplication.class, args);
    }
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页