【问题标题】:Connecting local spring boot app to google cloud SQL through google proxy通过google代理连接本地spring boot app到google cloud SQL
【发布时间】:2020-03-27 12:07:09
【问题描述】:

我是 Java/spring boot 的新手,我正在尝试使用 google 的云 SQL 作为我的项目的数据库。我已经下载了谷歌代理并使用谷歌云 SDK 进行了身份验证。当我启动代理并使用 SSMS 连接时,它会连接并正常工作。问题是当我尝试通过 spring boot 应用程序连接时出现错误。我不确定我是否在应用程序属性中遗漏了某些东西,或者忘记了导入依赖项或类似的东西。任何帮助,将不胜感激!我在下面包含了 applications.properties、build.gradle 和错误。谢谢!

Application.properties

spring.jpa.hibernate.ddl-auto=create spring.datasource.url=jdbc:mysql://127.0.0.1:1433/{DBNAME} spring.datasource.username={DMUSERNAME} spring.datasource.password={DMPASSWORD}

build.gradle

   id 'org.springframework.boot' version '2.2.1.RELEASE'
   id 'io.spring.dependency-management' version '1.0.8.RELEASE'
   id 'java'
}

group = '{GROUPNAME}'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
   compileOnly {
       extendsFrom annotationProcessor
   }
}

repositories {
   mavenCentral()
   maven { url 'https://repo.spring.io/milestone' }
}

ext {
   set('springCloudVersion', "Hoxton.RC2")
}

dependencies {
   implementation 'org.springframework.boot:spring-boot-starter-web'
   compileOnly 'org.projectlombok:lombok'
   annotationProcessor 'org.projectlombok:lombok'
   testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
   testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
   implementation 'org.springframework.cloud:spring-cloud-gcp-starter'
   implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
   runtime 'mysql:mysql-connector-java'
   implementation 'org.springframework.boot:spring-boot-starter-jdbc'

}

dependencyManagement {
   imports {
       mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
   }
}

test {
   useJUnitPlatform()
}

错误

  Caused by: java.net.ConnectException: Connection refused: no further information
  Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service 
  [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
  Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 
  'hibernate.dialect' not set
   Process 'command 'C:/Program Files/Java/jdk-13.0.1/bin/java.exe'' finished with non-zero exit value 1

【问题讨论】:

    标签: mysql spring-boot google-cloud-platform google-cloud-storage google-cloud-sql


    【解决方案1】:

    您使用的是哪个数据库?你的问题被标记为mysql

    端口 1433 用于 Microsoft SQL Server。 SSMS 适用于 Microsoft SQL Server

    您的连接字符串用于 MySQL 而不是 SQL Server。

    改变这个:

    spring.datasource.url=jdbc:mysql://127.0.0.1:1433/{DBNAME}
    

    到这里:

    spring.datasource.url=jdbc:sqlserver://127.0.0.1:1433/{DBNAME}
    

    上述连接字符串使用 TCP 套接字(而不是 Unix 套接字),并且要求 Cloud SQL 代理也使用 TCP 套接字设置。例如,当您以 TCP Socket 模式启动 Cloud SQL Proxy 时,它应该如下所示:

    ./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:1433
    

    由于您已通过 SSMS 成功连接,我假设您已为 Cloud SQL 访问设置了正确的角色。

    【讨论】:

      猜你喜欢
      • 2020-06-26
      • 1970-01-01
      • 2020-02-19
      • 2014-07-19
      • 1970-01-01
      • 2020-06-07
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多