servlet-springmvc+mybatis加载出错

问题描述

springmvc+mybatis加载出错

记录异常信息org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet successfully received from the server was 1,448,137,121,061 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.)
十一月 22, 2015 4:18:41 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [cloud_note] in context with path [/cloud_note] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet successfully received from the server was 1,448,137,121,061 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.)] with root cause
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.(Socket.java:425)
at java.net.Socket.(Socket.java:241)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:290)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2137)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:773)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:203)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
at org.tarena.note.service.UserServiceImpl$$EnhancerBySpringCGLIB$$f03df3a2.checkLogin()
at org.tarena.note.controller.user.LoginController.execute(LoginController.java:19)
at org.tarena.note.controller.user.LoginController$$FastClassBySpringCGLIB$$417a6ea9.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
at org.tarena.note.controller.user.LoginController$$EnhancerBySpringCGLIB$$ba3c6de3.execute()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apa
che.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

解决方案

1.确定服务是启着的
2.确定网络没问题.
3.其他软件没把oracle的端口占用,或配置文件里端口号没有写错。
4.把服务器的防火墙关了,再试一下。
5.是不是你数据库设置了最大连接,然后其他项目的连接池又把连接占用完了呢。
你这种情况应该是最后一点的原因;

解决方案二:

你的数据库连接时到本机的localhost吗?如果是的话,检查下本机的127.0.0.1的地址在hosts文件中配置127.0.0.1 localhost是否被注销了。
相同问题参考:http://blog.sina.com.cn/s/blog_75b0e2ad01017qeb.html

解决方案三:

数据源配置有问题,参考如下

com.mysql.jdbc.Driver

jdbc:mysql://192.168.1.252:3306/student?useUnicode=true&characterEncoding=utf8

root

tianma!@#

上面是用druid连接池,也可以用其他链接池,spring本身的

com.mysql.jdbc.Driver

jdbc:mysql://192.168.1.252:3306/student?useUnicode=true&charaterEncoding=utf-8

root

tianma!@#

<!-- myBatis文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
    <property name="mapperLocations" value="classpath:com/tm/openapi/mapper/*.xml" />
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com/tm/openapi/mapper" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

解决方案四:

很明显报的是数据库连接不上的错,数据库如果在本机,ip地址换成localhost试试,数据库在服务器上,首先ping下网通不通,然后本机连下服务器数据看看是否可以连上,解决了数据库连接问题,代码没问题。

时间: 2024-12-31 09:02:34

servlet-springmvc+mybatis加载出错的相关文章

深度学习-mnist 数据库 python 加载出错 !!

问题描述 mnist 数据库 python 加载出错 !! RT. Anaconda python 3.4 中 加载数据出错,显示:UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128) 代码如下: # dataset='mnist.pkl.gz' f = gzip.open(dataset, 'rb') train_set, valid_set, te

arm-ARM11开发板上insmod模块加载出错

问题描述 ARM11开发板上insmod模块加载出错 我在PC机上先编译好模块,然后移到开发板上,首次insmod成功. 然后我rmmod模块也成功了.但是当我再次insmod同一个模块时候报错. insmod: can't insert 'test.ko': File exists 试了多个模块都是这样的现象. 解决方案 http://bbs.csdn.net/topics/330145531 解决方案二: 你确定你rmmod成功了吗,lsmod看看 解决方案三: lsmd 应该还在

jq rid错误-JSP使用jqGrid加载出错

问题描述 JSP使用jqGrid加载出错 按照jqGrid官方文档和Demo准备搭建jqGrid开发环境,将下载包解压引入项目,准备按照官方Demo dropdown, checkbox, custom, etc 做个样例出来,但是出错了,一直报错,如下: 求大神指导这是啥问题呀! 解决方案 应该是配置不对,贴出完整代码看看.

web.xml 中的listener、 filter、servlet 加载顺序及其详解

在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰.         首先可以肯定的是,加载顺序与它们在 web.xml 文件中的先后顺序无关.即不会因为 filter 写在 listener 的前面而会先加载 filter.最终得出的结论是:listener -> filter -> servlet         同时还存在着这样一种配置节:context-pa

java-springmvc不能加载静态资源

问题描述 springmvc不能加载静态资源 ,用default servlet直接访问jsp页面可以,经过一个controller跳转到页面,页面又不能加载静态资源了, 解决方案 <mvc:resource也不合适,好像是路径有问题,有人能帮我看一下吗

jQuery简单实现图片预加载

    jQuery实现图片预加载:   我们在做网站的时候经常会遇到这样的问题:一个页面有大量的图片导致页面加载速度缓慢,经常会出现一个白页用户体验很不好.那么如何解决这个问题呢?下面我来介绍一种在实际应用中经常会使用到的js预加载的方法. JS代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 $(function(){ loadImg("fd039245d688d43f14f69eff7f1ed21b0ef43b5b.gif",ad

jquery加载XML文档代码分享

jquery加载XML文档代码分享,jquery代码如下. jquery加载XML文档 jquery代码如下 <script type="text/javascript"> $(function(){ $("#ajax").one('click',function(){ //$("#ajax").nextAll().remove(); $.ajax({ url: 'ajax.xml', //data: {id: 1, name: 0}

技巧文章:flash加载外部图片进度显示

技巧|加载|显示 //设置开始 loadfile="56.jpg";//要加载的文件 loadmc=_root.mymc;//要加载到的元件 setsize=300;//设置显示的宽度 (高度会等比显示) //设置结束 //---------代码开始------------ var my_mcl = new MovieClipLoader(); //定义新的MovieClipLoader对象 myListener = new Object(); //定义一个新的对象,用来监听load进

Jquery实现图片的预加载与延时加载

 有很多项目经常会需要判断图片加载完成后执行相应的操作,或者需要图片延迟加载,网上虽然已经有很不错的插件,但要为这些效果还得单独加载一个插件的话总感觉有点不舒服,干脆自己写了个方法:  代码如下    function loadimg(arr,funLoading,funOnLoad,funOnError){  var numLoaded=0,  numError=0,  isObject=Object.prototype.toString.call(arr)==="[object Object