亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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條經驗 獲得超6個贊

你必須改變很多東西

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條經驗 獲得超8個贊

這些是要檢查的東西

  1. 驗證數據庫服務器是否啟動并運行,以及您的連接詳細信息在獨立測試中是否正常工作。

  2. 如果不存在則授予訪問權限,請訪問:

不允許主機 'xxx.xx.xxx.xxx' 連接到此 MySQL 服務器

  1. 你為什么首先在 tomcat 中運行 spring boot 而不是作為一個胖罐?其次,mysql客戶端JAR應該包含在tomcat庫中

  2. 如果服務器可用連接不足,則增加 mySQL 最大連接數


查看完整回答
反對 回復 2022-12-21
  • 2 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號