为了账号安全,请及时绑定邮箱和手机立即绑定

Spring Boot、MySQL、Tomcat 无法在 Eclipse 中创建池的初始连接

Spring Boot、MySQL、Tomcat 无法在 Eclipse 中创建池的初始连接

尚方宝剑之说 2022-12-21 14:38:24
我在 Eclipse 中使用 Spring Boot 和 REST API 创建了一个 webapp。当我尝试使用 Tomcat 8 运行它时,它给出错误 “oatomcat.jdbc.pool.ConnectionPool:无法创建池的初始连接。”我尝试使用提供的解决方案,但似乎没有任何效果,它总是给出相同的错误。这是我的 application.properties 文件 -spring.datasource.url = jdbc:mysql://localhost:3306/dbase?autoReconnect=true&useSSL=falsespring.datasource.username = 1234spring.datasource.password = 1234spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialectspring.jpa.hibernate.ddl-auto = update这是 pom.xml 文件 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  <modelVersion>4.0.0</modelVersion>  <grouId>com.springboot</groupId>  <artifactId>springbootrestapi</artifactId>  <packaging>war</packaging>  <version>0.0.1-SNAPSHOT</version>  <name>springbootrestapiexample Maven Webapp</name>  <url>http://maven.apache.org</url>  <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>1.5.4.RELEASE</version>        <relativePath/> <!-- lookup parent from repository -->    </parent>  <dependencies>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>4.11</version>      <scope>test</scope>    </dependency>    <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-data-jpa</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>
查看完整描述

2 回答

?
杨魅力

TA贡献1811条经验 获得超5个赞

你必须改变很多东西

1.转到C盘中的mysql安装目录并找到my.ini文件。

将 default_authentication_plugin 更改为此

default_authentication_plugin=mysql_native_password
  1. 然后转到您的 MySQL 命令行客户端,登录后,运行此查询:

    ALTER USER 'yourusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';

然后重新启动 mysql 服务并运行你的程序。

"yourusername"和替换"yourpassword"为您实际的 MySQL 用户名和密码。

  1. 转到 POM 并替换:

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

使用最新的 MySQL8 连接器

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --><dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.15</version></dependency>

我希望它有所帮助 :)


查看完整回答
反对 回复 2022-12-21
?
料青山看我应如是

TA贡献1772条经验 获得超7个赞

这些是要检查的东西

  1. 验证数据库服务器是否启动并运行,以及您的连接详细信息在独立测试中是否正常工作。

  2. 如果不存在则授予访问权限,请访问:

不允许主机 'xxx.xx.xxx.xxx' 连接到此 MySQL 服务器

  1. 你为什么首先在 tomcat 中运行 spring boot 而不是作为一个胖罐?其次,mysql客户端JAR应该包含在tomcat库中

  2. 如果服务器可用连接不足,则增加 mySQL 最大连接数


查看完整回答
反对 回复 2022-12-21
  • 2 回答
  • 0 关注
  • 95 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信