D:\Java\Java19\bin\Java.exe...
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.1.1)
2023-07-08T20:35:07.824+08:00 INFO 11636 --- [ main] .e.j.JavaSpringBootWeb03ApplicationTests : Starting JavaSpringBootWeb03ApplicationTests using Java 19.0.2 with PID 11636 (D:\IDEA\Spring01\JavaSpringBoot_Web03\target\test-classes started by o in D:\IDEA\Spring01\JavaSpringBoot_Web03)
2023-07-08T20:35:07.829+08:00 INFO 11636 --- [ main] .e.j.JavaSpringBootWeb03ApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-07-08T20:35:09.273+08:00 WARN 11636 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.example.javaspringboot_web03]' package. Please check your configuration.
2023-07-08T20:35:10.178+08:00 INFO 11636 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-07-08T20:35:10.179+08:00 INFO 11636 --- [ main] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [2.0.3] using APR version [1.7.2].
2023-07-08T20:35:10.186+08:00 INFO 11636 --- [ main] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 3.0.8 7 Feb 2023]
2023-07-08T20:35:10.200+08:00 INFO 11636 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-07-08T20:35:10.201+08:00 INFO 11636 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.10]
2023-07-08T20:35:10.366+08:00 INFO 11636 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-07-08T20:35:10.369+08:00 INFO 11636 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2385 ms
2023-07-08T20:35:11.118+08:00 WARN 11636 --- [ 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]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
2023-07-08T20:35:11.123+08:00 INFO 11636 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-07-08T20:35:11.153+08:00 INFO 11636 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-07-08T20:35:11.189+08:00 ERROR 11636 --- [ 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配置web依赖或者Tomcat,自己试了一下,发现没有用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
还是自动退出
Process finished with exit code 1
最后我找了半天,才发现控制台有个:Error开头的句子,自己觉得这个应该是一个错误异常字样(主要是习惯了控制台爆红错误提示,没反应过来,本人新手)
自己 也不太懂,将下面几个句子复制到网上感觉杂乱无章,后来复制到ChatGPT提问
ChatGPT的回答是:
根据错误消息"Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.",可以推断出配置数据源时缺少了"url"属性,并且没有配置嵌入式数据源。
这是由于应用程序尝试配置数据源时未指定正确的数据库连接URL导致的。请确保在应用程序的配置文件(如application.properties或application.yml)中正确配置了数据库连接URL。
意思是说我没有配置数据库的链接,后来我去resources文件夹下的application.properties文档,双击打开配置数据库的url,如果是yml文件,可以去网上找教程yml配置数据库的URL方式
spring.datasource.url=jdbc:mysql://127.0.0.1:8080/你的数据库名字?characterEncoding=utf8
配置完之后,SpringBoot不在自动关闭,且也没有Error开头的句子段落:
使用软件发送请求,也没问题了。
IEDA控制台输出:Tom:10
总结:总的来说是我太过于依赖爆红报错提示,没想到它没有以爆红的方式报告错误,所以小伙伴们一定要吸取我的教训,学会查看操控台的输出日志,查看有没有错误提示,一般都是有错误提示(英语单词:Error--错误),另外,学到这里想要继续提升就得学英语了,因为像这个示例说明,想要阅读、学习新的开发工具、或者查询错误等,和英语离不开。不过可以先学会Java编程和框架再找到工作后再慢慢自学英语。