使用springcloud 和 连接池 连接orcale数据库报错,折磨一天了,请大佬解救,启动都正常的

数据库使用PLsql可以连接上,ping数据库主机也是通的。找了一天问题了,求大佬解救一下。基本可以排除数据库问题,现在迷了一天了,想早点下班。。。

报错信息:

2018-12-28 17:00:06.350 ERROR 21560 --- [http-nio-9661-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.NullPointerException
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:289) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:447) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at grp.pt.common.bs.CacheService$$EnhancerBySpringCGLIB$$14ccc726.putMap() ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at grp.pt.util.PublicSessionUtil.createSession(PublicSessionUtil.java:118) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at grp.pt.util.PublicSessionUtil.initSessionInfo(PublicSessionUtil.java:39) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at grp.util.session.UserSessionFilter.doFilter(UserSessionFilter.java:41) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.23.jar:8.5.23]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.23.jar:8.5.23]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
Caused by: java.lang.NullPointerException: null
at grp.pt.util.PublicSessionUtil.getDataSourceBeanKey(PublicSessionUtil.java:138) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at grp.pt.database.DynamicDataSource.determineCurrentLookupKey(DynamicDataSource.java:21) ~[grp-database-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.determineTargetDataSource(AbstractRoutingDataSource.java:196) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:164) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:246) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
... 46 common frames omitted

yml数据库配置内容

dynamicdata:
   #系统运行模式[Develop, Product]
    mode: Develop
    #默认数据源
    defaultKey: admdiv
    jndiName:
    data-sources:
    #数据源名: admdiv_年度_区划code
      admdiv:
        driverClassName: oracle.jdbc.driver.OracleDriver
        #url: jdbc:oracle:thin:@localhost:1521:orcl
        #driverClassName: com.mysql.jdbc.Driver
        #连接URL,协议+地址+Scheme
        #url: jdbc:mysql://localhost:3306/gap_ah?useUnicode=true&characterEncoding=utf8&useSSL=false
        username: yszx2018
        #密码
        password: a
        #数据库连接池配置样例
        url: jdbc:oracle:thin:@localhost:1521:orcl
        #连接池的最大连接数,-1为无限制
        maxActive: 8
        #最大空闲连接数,-1为无限制。注:如果是高负载系统,此值过低时可能会出现连接关闭的同时会打开新连接,连接池失效
        maxIdle: 8
        #在连接池满的情况下最长等待时间(毫秒),如果超时则抛异常,-1为一直等待
        maxWait: -1
        #初始连接数
        initialSize: 8
        #自动回收超时连接
        removeAbandoned: true
        #自动回收超时时间(以秒数为单位)
        removeAbandonedTimeout: 3600000
        #是否要进行检测
        testWhileIdle: true
        #进行检测一个连接是有效的SQL语句,比如oracle是select 1 from dual 而 mysql是 select 1
        validationQuery: select 1 from dual
        #每隔多少时间检测一次,比如每半小时检测一次,总不能总是检测,这会对性能产生影响
        timeBetweenEvictionRunsMillis: 180000
        #每次检测时,需要检测多少个数据连接,一般设置为与最大连接数一样,这样就可以检测完所有的连接
        numTestsPerEvictionRun: 8
        #一个数据库连接连接多少时间之外,我们认为其应该不再适用了(可能下一次就会失效了),应该移除并重新建立连接了
        minEvictableIdleTimeMillis: 3600000
0

1个回答

spring提供了在spring上下文中配置数据源Bean的多种方式,包括:

a.通过JDBC驱动程序定义的数据源;

b.通过JNDI查找的数据源;

c.连接池的数据源;

接下我们就专门来讲讲从使用连接池获取连接的数据源!(即c点)

上下文配置Bean的代码:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
    <property name="username" value="wwo"/>
    <property name="password" value="wwo"/>
    <!-- 连接池启动时的初始值 -->
    <property name="initialSize" value="3" />
    <!-- 连接池的最大值 -->
    <property name="maxActive" value="300" />
    <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
    <property name="maxIdle" value="2" />
    <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
    <property name="minIdle" value="1" />
    <!-- end -->
</bean>

注:JDBC驱动数据源并没有池的概念,因此没有存在池属性的配置!

0
qq_34846007
迷途菜鸡 但是把连接池配置都去掉,还是一样的结果,报的错也一样的
6 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!

相似问题

1
使用springcloud 和 连接池 连接orcale数据库报错,折磨一天了,请大佬解救,启动都正常的
2
这段“锁死springcloud版本”的配置有什么问题?为什么在父工程里添加了它之后,某个随机的子模块会报错?
3
Spring整合Mybatis如何使用xml文件配置sql语句
4
AspectJ基于注解报错,哪位老哥帮忙看一下
0
使用Atomikos做DB2的分布式事务,我使用的是谁的连接池?
1
jpa使用@Query查询报错SQL Error: 1064, SQLState: 42000
0
如何使用web接口高效传输10M以上较大的json数据
1
在虚拟机安装elasticsearch并浏览器输入http://虚拟机ip:9200连接成功后,postman无法新增索引
0
SpringCloud GateWay 自定义GatewayFilterFactory时如何读取body体中内容?
0
求大佬解决解决解决springsecurity资源权限缓存问题
1
请问 JPA 怎么使用左连接呀
3
数据库的数据无法在jsp中显示出来
1
我想最快速用SSM制作一个登录验证,COPY也行,网上也搜过了,但是导进去各种报错,该怎么办。
0
使用activiti工作流时,发动流程报的错,求大神解
0
使用activiti工作流时,部署流程,发动流程,启动流程。。。。都会报这个错,求大神解决
1
java 连接sqlserver2008 r2连接不上问题
0
springboot如何使用geowebcache
3
spring mvc 4.0.0 release版执行一个post方法报错
2
IDEA使用求助:标红下划线, can not access org.springframework.beans.factory.aware ,但项目启动没问题;
2
使用Criteria.list( )赋值给list,list值为空,这是什么原因?