问题遇到的现象和发生背景
问题背景:
一个网关项目是C写的,不是本人写的,一个Java项目搭配前端本人所写.数据库sqlite3,连接池druid
(前端项目,java项目,网关项目,sqlite3数据库全都在一台电脑上)
调用链路:
前端表单传递数据到后台java,java传递数据到网关,网关执行操作写数据库,java只负责读数据库
问题接口:
一个功能是修改网关所在linux系统的IP地址:比如从192.168.10.221修改到192.168.10.222
接口功能:
修改完IP之后,前端接受一个200的返回值,然后重新打开一个页签,地址是修改后的IP
问提描述:
1.网关项目接到修改的IP以后执行成功了,但是返回值丢了,也就是说前端收不到java返回的200状态码,无法实现跳转
2.(最棘手的问题)网关改变本机IP以后,导致java的数据库连接池断掉了,不管怎么刷新前端页面都会报错,报错代码如下:
问题内容:
用代码块功能插入代码,请勿粘贴截图
(部分配置文件的代码)
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: org.sqlite.JDBC
url: jdbc:sqlite:D:/sqlite/test.db
druid:
initialSize: 5
minIdle: 10
maxActive: 20
mybatis-plus:
configLocation: classpath:mybatis/mybatis-config.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
type-aliases-package: com.wutron..domain
mapper-locations: classpath:/mapper/*/*Dao.xml
运行结果及报错内容
20:39:24.367 [http-nio-8088-exec-27] ERROR c.w.f.w.e.GlobalExceptionHandler - [notFount,64] - ?????:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.IllegalStateException: call() called in inappropriate state**
The error may exist in URL [jar:file:/opt/plateform/gateway-admin.jar!/BOOT-INF/lib/gateway-system-1.0.0.jar!/mapper/system/SysDeployDao.xml]
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: select sys_deploy_id SysDeployId, ... , code from sysd where 1=1 and type = ?
Cause: java.lang.IllegalStateException: call() called in inappropriate state
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy90.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:173)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:78)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
at com.sun.proxy.$Proxy100.selectSysDeployList(Unknown Source)
at com.wutron.system.service.impl.SysDeployServiceImpl.getDeployCode(SysDeployServiceImpl.java:46)
我的解答思路和尝试过的方法
我的想法是,捕获异常,如果出现异常则直接重新创建数据库连接,这样能将断掉的数据库连接丢掉(配置文件的形式不会做!)
或者自己手动创建JDBC连接(代码形式做起来也挺困难,能直接给例子更好)
我想要达到的结果
1.前端修改IP成功之后,能实现跳转,重新打开页签,IP地址是修改后的地址(这个问题不是那么紧急)
2.网关成功修改IP之后,数据库连接依然可用(无论什么方式都行,只要查询sql不会报错,现在是只能重启java才能解决!)
3.最好有人和我说下为什么sqlite3,一个本机的绝对路径数据库,会因为IP的改变产生如此之大的影响,能和我讲请原理的,有额外奖励