java项目windows下能连接linux上的数据库,部署到linux反而连不上了

花末 2017-03-21 04:44:32
请问一下,我在linux远程主机上装有mysql,我的java项目在windows下运行能连接到该数据库,但是部署到linux后却连不上数据库了,怎么回事啊,请大神指教

报错信息如下:
HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

type Exception report

message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
### The error may exist in file [/usr/tomcat8/webapps/ROOT/WEB-INF/classes/mapper/ThinkDao.xml]
### The error may involve com.lgor.dao.ThinkDao.getThinkList
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:979)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
### The error may exist in file [/usr/tomcat8/webapps/ROOT/WEB-INF/classes/mapper/ThinkDao.xml]
### The error may involve com.lgor.dao.ThinkDao.getThinkList
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76)
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)
com.sun.proxy.$Proxy35.selectList(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205)
org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
com.sun.proxy.$Proxy36.getThinkList(Unknown Source)
com.lgor.service.impl.ThinkServiceImpl.getThinkList(ThinkServiceImpl.java:29)
com.lgor.web.ThinkController.getThinkList(ThinkController.java:40)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
...全文
934 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
陆丕山 2018-01-11
  • 打赏
  • 举报
回复
http://blog.csdn.net/noname666/article/details/78420037
tianfang 2017-03-22
  • 打赏
  • 举报
回复
JDBC 串贴一下 还有就是mysql数据库的用户授权,用户名还有用户主机,localhost和127.0.0.1都是不一样的
showhunter74 2017-03-21
  • 打赏
  • 举报
回复
引用 6 楼 luckglee 的回复:
[quote=引用 5 楼 showhunter74 的回复:] [quote=引用 3 楼 luckglee 的回复:] [quote=引用 1 楼 showhunter74 的回复:] 你的异常说的是连接数据库异常。如果你的数据库连接配置从windows 访问linux无异常的话。 请检查一下你新linux环境的网络情况。是否允许远程访问,linux存在双向防火墙,发出信息如接受信息都可能设置防火墙
数据库和项目是在同一台主机上的,我在windows上测试项目的时候能够连接上linux的数据库。但是我把项目部署到linux上后,就报错了[/quote] 这个跟你是不是在一台linux主机上木有关系。因为你的项目是根据IP去请求的。[/quote] 部署在Linux上的项目,其他没有连接数据库的url都是可用的,只有连接了数据库的url报错。并且我在windows上可以访问到在linux的数据库啊,ping ip 也通的 [/quote] 我的意思是linux对外发送信息的防火墙策略,你是否有检查。linux访问不出去的情况。。
花末 2017-03-21
  • 打赏
  • 举报
回复
引用 5 楼 showhunter74 的回复:
[quote=引用 3 楼 luckglee 的回复:] [quote=引用 1 楼 showhunter74 的回复:] 你的异常说的是连接数据库异常。如果你的数据库连接配置从windows 访问linux无异常的话。 请检查一下你新linux环境的网络情况。是否允许远程访问,linux存在双向防火墙,发出信息如接受信息都可能设置防火墙
数据库和项目是在同一台主机上的,我在windows上测试项目的时候能够连接上linux的数据库。但是我把项目部署到linux上后,就报错了[/quote] 这个跟你是不是在一台linux主机上木有关系。因为你的项目是根据IP去请求的。[/quote] 部署在Linux上的项目,其他没有连接数据库的url都是可用的,只有连接了数据库的url报错。并且我在windows上可以访问到在linux的数据库啊,ping ip 也通的
showhunter74 2017-03-21
  • 打赏
  • 举报
回复
引用 3 楼 luckglee 的回复:
[quote=引用 1 楼 showhunter74 的回复:] 你的异常说的是连接数据库异常。如果你的数据库连接配置从windows 访问linux无异常的话。 请检查一下你新linux环境的网络情况。是否允许远程访问,linux存在双向防火墙,发出信息如接受信息都可能设置防火墙
数据库和项目是在同一台主机上的,我在windows上测试项目的时候能够连接上linux的数据库。但是我把项目部署到linux上后,就报错了[/quote] 这个跟你是不是在一台linux主机上木有关系。因为你的项目是根据IP去请求的。
花末 2017-03-21
  • 打赏
  • 举报
回复
引用 2 楼 qq_30831935 的回复:
1、部署java项目的机器能ping通部署mysql的机器吗? 2、mysql开了吧?
数据库和项目是在同一台Linux主机上的,我在windows上测试项目的时候能够连接上linux的数据库。但是我把项目部署到linux上后,就报错了
花末 2017-03-21
  • 打赏
  • 举报
回复
引用 1 楼 showhunter74 的回复:
你的异常说的是连接数据库异常。如果你的数据库连接配置从windows 访问linux无异常的话。 请检查一下你新linux环境的网络情况。是否允许远程访问,linux存在双向防火墙,发出信息如接受信息都可能设置防火墙
数据库和项目是在同一台主机上的,我在windows上测试项目的时候能够连接上linux的数据库。但是我把项目部署到linux上后,就报错了
鱿鱼ing 2017-03-21
  • 打赏
  • 举报
回复
1、部署java项目的机器能ping通部署mysql的机器吗? 2、mysql开了吧?
showhunter74 2017-03-21
  • 打赏
  • 举报
回复
你的异常说的是连接数据库异常。如果你的数据库连接配置从windows 访问linux无异常的话。 请检查一下你新linux环境的网络情况。是否允许远程访问,linux存在双向防火墙,发出信息如接受信息都可能设置防火墙

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧