【问题标题】:Spring using windows user instead of given username 'root' to hit the mysqlSpring使用windows用户而不是给定的用户名'root'来访问mysql
【发布时间】:2018-07-05 12:24:00
【问题描述】:

得到错误

“用户'DEll'@'localhost'的访问被拒绝(使用密码:YES)”

在 spring xml 文件中,我将用户指定为“root”而不是戴尔。我已经尝试了一切。我相信会有一个简单的解决方案。

<bean id="dataSource"
class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="${driverClassName}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
</bean>

属性文件是

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
username=root
password=12345

【问题讨论】:

  • 没有。我想澄清一下,我的问题是 spring 正在使用 windows 'Dell' 用户来访问 mysql 数据库,而不是配置文件中的给定 mysql 用户,即 'root。
  • 这种事不会再发生了Windows username to DB username?
  • 您确定用户有权访问数据库吗?
  • spring配置文件中给出的DB用户名 spring应该使用spring xml中给出的用户名。

标签: mysql spring spring-jdbc apache-commons-dbcp


【解决方案1】:

您似乎发现USERNAME 已经是一个保留的系统环境变量。可能是因为你在windows上,不区分大小写就是找小写的版本

尝试更改您的属性和引用:

user=root&lt;property name="username" value="${user}"&gt;&lt;/property&gt;

【讨论】:

    猜你喜欢
    • 2016-06-12
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    相关资源
    最近更新 更多