简体   繁体   English

Spring Boot无法从application.properties加载用户名

[英]Spring Boot not loading username from application.properties

I'm developing a simple web application with spring boot. 我正在用Spring Boot开发一个简单的Web应用程序。 In the first step, I implemented everything about the page itself and a simple login. 在第一步中,我实现了有关页面本身和简单登录的所有内容。 Additionally, I implemented a database access using mysql and hibernate. 另外,我使用mysql和hibernate实现了数据库访问。 My database runs on a local easyphp devserver. 我的数据库在本地easyphp devserver上运行。

In the first step, everything worked fine. 第一步,一切正常。 However, after a reset of the database and recreating the user with the same credentials, Hibernate is not able to get a connection: 但是,在重置数据库并使用相同的凭据重新创建用户后,Hibernate无法获得连接:

2018-02-09 21:17:11.487 ERROR 9592 --- [  restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'db'

As I can understand, no username was configured. 据我了解,没有配置用户名。 But in my application.properties , a username is set: 但是在我的application.properties ,设置了用户名:

spring.datasource.url=jdbc:mysql://localhost:3306/db?userSSL=false
spring.datasource.username=user
spring.datasource.password=

The exception occurres on startup, so it has to be the configuration. 异常发生在启动时,因此必须是配置。 At the database, the user 'user' has all priviliges at the database 'db' , but no one on others. 在数据库中,用户'user'具有数据库'db'所有特权,但没有其他特权。

The data source URL might be causing the issue. 数据源URL可能是导致此问题的原因。 Is that a typo? 那是错字吗? Can you check by resetting it to the following? 您可以通过将其重置为以下内容进行检查吗? It has to be "useSSL" instead of "userSSL" 它必须是“ useSSL”而不是“ userSSL”

spring.datasource.url=jdbc:mysql://localhost:3306/db?useSSL=false
spring.datasource.username=user
spring.datasource.password=

If the above does not work, your problem might be related to permissions for the user. 如果上述方法不起作用,则您的问题可能与用户权限有关。 A question posted here relates to yours (although it is in PHP). 这里发布的问题与您的问题有关(尽管在PHP中)。

Hopefully this resolves it, let us know. 希望这能解决它,让我们知道。

Ok, found the solution by myself. 好的,我自己找到了解决方案。 The real username contained a '_' like 'user_name'. 真实的用户名包含“ _”,例如“ user_name”。 Somehow this character was the problem why the username was not read. 不知何故,此字符是为什么未读取用户名的问题。

Edit: Worked a few times, but the problem still exists... 编辑:工作了几次,但问题仍然存在...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM