此时尝试在Google云平台上部署一个简单的Java应用程序。但目前只有起始页(登录(和注册页面处于打开状态。当我尝试注册新用户时,出现错误:
org.springframework.orm.jpa.JpaSystemException: Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException (HibernateJpaDialect.java:244)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible (HibernateJpaDialect.java:155)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible (AbstractEntityManagerFactoryBean.java:417)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible (ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary (DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke (PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke (CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke (ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke (JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy42.findByUsername (Unknown Source)
at project.security.service.UserServiceImpl.findByUsername (UserServiceImpl.java:38)
at project.security.validator.UserValidator.validate (UserValidator.java:32)
at project.security.controller.UserController.registration (UserController.java:38)
我知道访问数据库的问题是"云MySQL"。'我无法理解我做错了什么。当我在本地服务器上运行应用程序时,一切正常。我尝试了运行应用程序的各种选项,但错误总是相同的。链接到代码 https://github.com/Ditrim023/MVC_for_money。 指向无法正常工作的应用程序 change-curr.appspot.com 的链接。我会很高兴得到任何帮助。
按照 Google Cloud 的 java 文档,您的属性文件中有一个无效的连接字符串。
您已定义:
JDBC:Google:MySQL://exchange-6/Secur?user=root
在文档中,尝试使用
String jdbcUrl = String.format(
"jdbc:mysql://google/%s?cloudSqlInstance=%s&"
+ "socketFactory=com.google.cloud.sql.mysql.SocketFactory",
databaseName,
instanceConnectionName);
确保在 Google Cloud 中已将您的 IP 地址添加到数据库权限中。或者添加 0.0.0.0/0 以允许任何 IP 地址连接到您的数据库。但是,不建议这样做。