zoukankan      html  css  js  c++  java
  • Spring容器使用中出现 Access denied for user 'Administrator'@'localhost' (using password: YES)

    Access denied for user 'Administrator'@'localhost' (using password: YES)一个问题找原因找了很久,终于找到了

    在Spring容器中通过配置 <context:property-placeholder location="classpath:/jdbc.properties"/> 调用properties数据源配置文件时出现 Access denied for user 'Administrator'@'localhost' (using password: YES) 错误!!!!

    Properties配置:

    Spring基本配置(完成注入):

    错误原因:

      在系统中也有个username属性,这时系统变量覆盖了Properties中的值,这时取得username的值为系统的用户名Administrator,密码为properties中的password去查询数据库,此时用户名名和密码并不匹配就会报错。在Spring完成注入时是用 "${..}"  方式获取值完成注入的。而通过这种表达式也能直接获取到JVM系统属性..........

    解决方案:

      方案一:将properties文件中的username换成user或其他就字符串就可以成功获取连接访问数据库。建议:username时敏感词汇,为了安全起见还是尽量不要使用username。

      方案二:在Spring配置文件中修改成:<context:property-placeholder location="classpath:/jdbc.properties" system-properties-mode="FALLBACK / NEVER"/>   

          添加一个system-properties-mode属性

          该属性有三个值:FALLBACK  --- 默认值,不存在时覆盖

                  NEVER      --- 不覆盖

                  OVERRIDE  --- 覆盖

     

  • 相关阅读:
    题解 P2647 【最大收益】
    CF817E Choosing The Commander
    P2922 [USACO08DEC]Secret Message G
    洛谷月赛 P7107 天选之人
    如何在考场上快速用C++写高级对拍器
    题解 CF527D 【Clique Problem】
    P6768 [USACO05MAR]Ombrophobic Bovines 发抖的牛
    [USACO06NOV]Corn Fields G
    Orz 教主的比赛题解
    JZOI 4311 统一天下
  • 原文地址:https://www.cnblogs.com/xss512/p/10947194.html
Copyright © 2011-2022 走看看