在运行docker时,我得到了'java.sql.SQLNonTransientConnectionException:不允许公共(public)密钥检索'。我正在使用jhipster整体项目。并且我已经尝试过'allowPublicKeyRetrieval = true'解决方案。如果正在使用,则意味着又得到了一个更多错误,例如“用户'root'@'localhost'的访问被拒绝。请帮助我解决此错误。我从1周开始就遇到了同样的问题。

这是我的.yo-rc.json

{
 "generator-jhipster": {
"promptValues": {
  "packageName": "com.niche.ng",
  "nativeLanguage": "en"
},
"jhipsterVersion": "6.5.0",
"applicationType": "monolith",
"baseName": "Nichehands",
"packageName": "com.niche.ng",
"packageFolder": "com/niche/ng",
"serverPort": "8080",
"authenticationType": "session",
"cacheProvider": "ehcache",
"enableHibernateCache": false,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"rememberMeKey": "b9f603400b9bd1cf887c6efbba0e8e3822cf735d083441758e81667adef95db8af19462970cfece6048f0be25cc",
"embeddableLaunchScript": false,
"useSass": true,
"clientPackageManager": "npm",
"clientFramework": "angularX",
"clientTheme": "none",
"clientThemeVariant": "",
"testFrameworks": [],
"jhiPrefix": "jhi",
"entitySuffix": "",
"dtoSuffix": "DTO",
"otherModules": [],
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
  "en",
  "hi",
  "ta",
  "te"
],
"blueprints": []
}
}

最佳答案

可能的原因:

  • 您想以root用户身份使用db连接,这是个坏主意,因为root可以使用所有特权访问所有数据库表。在某些情况下,您想将对db中特定资源的访问权限添加到应用程序。
  • 您正在使用数据库的无密码连接

  • 可能的解决方案:
  • 例如在您的db shell中添加数据库用户(无root):
    CREATE USER 'apppuser'@'localhost' IDENTIFIED BY 'topsecret';CREATE USER 'apppuser'@'%' IDENTIFIED BY 'topsecret';GRANT SELECT ON dbname.* to 'apppuser'@'localhost';GRANT INSERT ON dbname.* to 'apppuser'@'localhost';GRANT UPDATE ON dbname.* to 'apppuser'@'localhost';GRANT DELETE ON dbname.* to 'apppuser'@'localhost';GRANT SELECT ON dbname.* to 'apppuser'@'%';GRANT INSERT ON dbname.* to 'apppuser'@'%';GRANT UPDATE ON dbname.* to 'apppuser'@'%';GRANT DELETE ON dbname.* to 'apppuser'@'%';
    然后更改您的docker-compose凭证
  • 与第一个有关。在docker-compose文件路径中创建.env文件并添加属性:
    DBUSER='apppuser'DBPASSWORD='topsecret'
    然后在您的docker-compose文件中将此变量添加为${DBUSER} and ${DBPASSWORD}
  • 与第二点有关。如果您在使用.env文件时遇到问题,并且正在使用linux系统,则可以像在.env文件中一样,在/etc/environment中添加环境属性。请记住,不能将属性与'#'一起使用,因为它将被视为注释。

  • 请发送您的docker-compose文件和production.yml文件。

    08-06 21:24