Java 无法创建 PoolableConnectionFactory(用户 'root'@'localhost' 的访问被拒绝(使用密码:YES))
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3299317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
提问by James
I recently deployed a working webapp on my localhost to amazon web services. The problem i'm encountering is - though context.xml has username as 'james', the exception stacktrace mentions otherwise.
我最近在我的本地主机上部署了一个工作 web 应用程序到亚马逊 web 服务。我遇到的问题是 - 尽管 context.xml 的用户名是“james”,但异常堆栈跟踪另有说明。
org.apache.jasper.JasperException: org.apache.jasper.JasperException: org.apache.jasper.JasperException: javax.servlet.ServletException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
It is trying to connect to database with username 'root'. It it be because of caching of the file(context.xml)? How do I tackle that? I have restarted the web server as well, but it's not coming to effect.
它正在尝试使用用户名“root”连接到数据库。是因为文件(context.xml)的缓存?我该如何解决?我也重新启动了 web 服务器,但它没有生效。
Thanks in Advance.
提前致谢。
EDIT:
EDIT:
Here's the content of context.xml:
这是 context.xml 的内容:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
<Resource
name="jdbc/NetmarketDB"
auth="Container"
type="javax.sql.DataSource"
removeAbandoned="true"
removeAbandonedTimeout="30"
maxActive="100"
maxIdle="30"
maxWait="1000"
username="james"
password="xxxxxxxxxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/ams"/>
</Context>
You can see it happening by clicking on Login
or Register
on the page:
http://184.73.118.76/Links.jsp
您可以通过单击Login
或Register
在页面上看到它的发生:http:
//184.73.118.76/Links.jsp
Is there anything I need to do to bring context.xml changes to effect?
I have carried out two actions:
1. touch web.xml
in WEB-INF
2. Restart tomcat server.
我需要做些什么才能使 context.xml 更改生效?我进行了两个动作:
1.touch web.xml
在WEB-INF中
2.重启tomcat服务器。
Desperately need help here.
在这里迫切需要帮助。
Thanks again. James.
再次感谢。詹姆士。
回答by hendry.fu
Check your $CATALINA_BASE/conf/[enginename]/[hostname]/[webapp].xml, on default Tomcat this should be $CATALINA_BASE/conf/Catalina/localhost/[webapp].xml, tomcat create a copy of your context.xml and this probably was not updated when you update your context.xml
检查您的 $CATALINA_BASE/conf/[enginename]/[hostname]/[webapp].xml,在默认 Tomcat 上,这应该是 $CATALINA_BASE/conf/Catalina/localhost/[webapp].xml,tomcat 创建您的上下文的副本。 xml,当您更新 context.xml 时,这可能没有更新
Tomcat Context Container Reference
$CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase.
$CATALINA_BASE/conf/[enginename]/[hostname]/,在应用程序文件中 /META-INF/context.xml 的单个文件中。如果 Web 应用程序打包为 WAR,则 /META-INF/context.xml 将被复制到 $CATALINA_BASE/conf/[enginename]/[hostname]/ 并重命名以匹配应用程序的上下文路径。一旦此文件存在,如果在主机的 appBase 中放置了具有较新 /META-INF/context.xml 的新 WAR,它将不会被替换。
回答by Jeshurun
Make sure there isn't a file named $CATALINA_BASE/conf/Catalina/localhost/yourapp.xml or that it doesn't contain another datasource definition to the same database with the username 'james'.
确保没有名为 $CATALINA_BASE/conf/Catalina/localhost/yourapp.xml 的文件,或者它不包含用户名为“james”的同一数据库的另一个数据源定义。