首页 > 数据库 >【springboot】springboot集成mysql

【springboot】springboot集成mysql

时间:2023-07-02 19:00:13浏览次数:42  
标签:集成 02 springboot 18 2023 --- mysql restartedMain 07

pom.xml增加依赖的坐标

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.3.1</version>
</dependency>

<!--        <dependency>-->
<!--            <groupId>com.mysql</groupId>-->
<!--            <artifactId>mysql-connector-j</artifactId>-->
<!--            <scope>runtime</scope>-->
<!--        </dependency>-->

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.26</version>
    <scope>runtime</scope>
</dependency>

报错如下:

18:42:43.414 [Thread-1] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@5d1c613f

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::      (v2.7.14-SNAPSHOT)

2023-07-02 18:42:43.653  INFO 73321 --- [  restartedMain] com.oo2.oo2.Oo2Application               : Starting Oo2Application using Java 1.8.0_361 on JAMESSHI-MB2 with PID 73321 (/Users/jamesshi/java/oo2/target/classes started by jamesshi in /Users/jamesshi/java/oo2)
2023-07-02 18:42:43.654  INFO 73321 --- [  restartedMain] com.oo2.oo2.Oo2Application               : No active profile set, falling back to 1 default profile: "default"
2023-07-02 18:42:43.682  INFO 73321 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-07-02 18:42:43.682  INFO 73321 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-07-02 18:42:44.102  WARN 73321 --- [  restartedMain] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.oo2.oo2]' package. Please check your configuration.
2023-07-02 18:42:44.459  INFO 73321 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8885 (http)
2023-07-02 18:42:44.464  INFO 73321 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-07-02 18:42:44.465  INFO 73321 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.76]
2023-07-02 18:42:44.508  INFO 73321 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-07-02 18:42:44.509  INFO 73321 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 827 ms
2023-07-02 18:42:44.751  WARN 73321 --- [  restartedMain] 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
2023-07-02 18:42:44.753  INFO 73321 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-07-02 18:42:44.769  INFO 73321 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-07-02 18:42:44.791 ERROR 73321 --- [  restartedMain] 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 0

这是因为配置文件application.properties里面没有配置mysql对应的信息

spring.datasource.url=jdbc:mysql://localhost:3306?characterEncoding=UTF8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=12345678
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

这次可以启动成功了

18:49:25.626 [Thread-1] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@5d1c613f

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::      (v2.7.14-SNAPSHOT)

2023-07-02 18:49:25.916  INFO 75190 --- [  restartedMain] com.oo2.oo2.Oo2Application               : Starting Oo2Application using Java 1.8.0_361 on JAMESSHI-MB2 with PID 75190 (/Users/jamesshi/java/oo2/target/classes started by jamesshi in /Users/jamesshi/java/oo2)
2023-07-02 18:49:25.917  INFO 75190 --- [  restartedMain] com.oo2.oo2.Oo2Application               : No active profile set, falling back to 1 default profile: "default"
2023-07-02 18:49:25.957  INFO 75190 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-07-02 18:49:25.957  INFO 75190 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-07-02 18:49:26.541  WARN 75190 --- [  restartedMain] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.oo2.oo2]' package. Please check your configuration.
2023-07-02 18:49:26.990  INFO 75190 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8885 (http)
2023-07-02 18:49:26.998  INFO 75190 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-07-02 18:49:26.999  INFO 75190 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.76]
2023-07-02 18:49:27.072  INFO 75190 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-07-02 18:49:27.073  INFO 75190 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1116 ms
2023-07-02 18:49:27.540  INFO 75190 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2023-07-02 18:49:27.582  INFO 75190 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8885 (http) with context path ''
2023-07-02 18:49:27.591  INFO 75190 --- [  restartedMain] com.oo2.oo2.Oo2Application               : Started Oo2Application in 1.959 seconds (JVM running for 2.464)

标签:集成,02,springboot,18,2023,---,mysql,restartedMain,07
From: https://www.cnblogs.com/abc-begin/p/17521203.html

相关文章

  • MySql —— 数据页与索引
    数据库的I/O操作的最小单位是页,InnoDB数据页的默认大小是16KB,意味着数据库每次读写都是以16KB为单位的,一次最少从磁盘中读取16K的内容到内存中,一次最少把内存中的16K内容刷新到磁盘中。数据页包括七个部分       在FileHeader中有两个指针,分别指向上......
  • springboot使用拦截器
    要用拦截器必须要将实现HandlerInterceptor的拦截器注册到InterceptorRegistry对象中。需要先写一个拦截器,规则:实现HandlerInterceptor作用:在请求的处理过程中添加自定义的逻辑。preHandle():在请求被处理之前执行的逻辑,可以通过返回值决定是否继续处理请求。postHandle():......
  • mysql在新建用户时报错ERROR 1819
    问题描述:mysql在新建用户时报错ERROR1819,如下所示:数据库:mysql5.7.42系统:rhel7.31、问题重现mysql>grantreplicationslave,replicationclienton*.*to'slave'@'192.168.133.91'identifiedby"slave@12345";ERROR1819(HY000):Yourpassworddoe......
  • 面试官问我知不知道 MySQL 的锁,5分钟让他刮目相看是什么?一篇理解
    锁的概念锁机制是用于管理对共享资源的并发访问。InnoDB存储引擎会在行级别上对数据上锁。数据库使用锁是为了支持对共享资源进行并发访问,提供数据的完整性和一致性。lock与latchlatch一般称为闩锁(轻量级的锁),因为其要求锁定的时间必须要非常短。在innoDB存储引擎中,latch可以分为......
  • Mysql基础篇(三)之多表查询
    一.多表关系一对多(多对一)多对一一对一1.一对多(1).案例:部门与员工的关系(2).关系:一个部门对应多个员工,一个员工对应一个部门(3).实现:在多的一方建立外建,指向一的一方的主键2.多对多(1).案例:学生与课程的关系(2).关系:一个学生可以选修多门课程,一门课程也......
  • 面试官问我知不知道 MySQL 的锁,5分钟让他刮目相看
    锁的概念锁机制是用于管理对共享资源的并发访问。InnoDB存储引擎会在行级别上对数据上锁。数据库使用锁是为了支持对共享资源进行并发访问,提供数据的完整性和一致性。lock与latchlatch一般称为闩锁(轻量级的锁),因为其要求锁定的时间必须要非常短。在innoDB存储引擎中,latch可以......
  • MySQL安装
    MySQL5.7的安装下载地址https://dev.mysql.com/downloads/windows/installer/5.7.html选择GAversion稳定正式版在这里卸载!在这里卸载!在这里卸载!环境变量配置win+r键入sysdm.cpl选择-高级->环境变量系统变量->新建......
  • dotnet-微服务学习-dotnet集成SkyWaking链路追踪
    关于链路追踪的原来我们单独开一篇文章讲解这里我们来讲解SkyWaking的安装和集成 首先进入SkyWaking官网下载最新的包网址如下: https://skywalking.apache.org/downloads/ 1.1windows安装下载后Winwos直接运行双击bin目录下的startup.bat即可 注意 SkyWalk......
  • SpringBoot 插件化开发模式
    1、Java常用插件实现方案1.2、serviceloader方式serviceloader是java提供的spi模式的实现。按照接口开发实现类,而后配置,java通过ServiceLoader来实现统一接口不同实现的依次调用。而java中最经典的serviceloader的使用就是Java的spi机制。1.2.1、javaspiSPI全称ServiceProv......
  • 部署springboot项目到linux服务器
    1.使用Xshell连接服务器xshell免费版地址:家庭/学校免费-NetSarangWebsite(xshell.com)2.安装java运行环境sudoaptinstallopenjdk-8-jdk3.使用xftp上传后端jar包文件xftp免费版地址:家庭/学校免费-NetSarangWebsite(xshell.com)4.在xshell中使用命令......