这是我第一次使用Spring Boot和Tomcat8。在Tomcat服务器上部署后,我遇到问题,我无法获取JNDI数据源的实例。
在日志文件中,我看到错误
检索数据库元数据时出错;嵌套的异常是org.springframework.jdbc.support.MetaDataAccessException:无法获取用于提取元数据的Connection。嵌套的异常是org.springframework.jdbc.CannotGetJdbcConnectionException:无法获取JDBC连接。嵌套异常是java.sql.SQLException:数据源已关闭
下面是来自server.xml和Context.xml的代码
*** Server.xml ***
<Resource name="jdbc/jndiDs" global="jdbc/jndiDs" auth="Container" type="javax.sql.DataSource" maxActive="50" maxIdle="30" maxWait="10000" driverClassName="oracle.jdbc.driver.OracleDriver" url="connection url" username="username" password="password" />
***Context.xml ***
<ResourceLink name="jdbc/jndiDs" global="jdbc/jndiDs" auth="Container" type="javax.sql.DataSource" />
但是,当我在配置类中将DriverManagerDataSource用作bean时,它可以正常工作。
下面是用于使用存储过程插入数据的Java代码
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate).withProcedureName("COP00166_001_1.Capture")
.withoutProcedureColumnMetaDataAccess();
call.declareParameters(new SqlParameter("sPMsgTx", Types.VARCHAR),
new SqlParameter("sPConLegacyId", Types.VARCHAR),
new SqlParameter("nPConId", Types.INTEGER),
new SqlParameter("nPPceNr", Types.INTEGER),
new SqlParameter("nPBulCsysIdCorig", Types.INTEGER),
new SqlParameter("nPBulCsysIdOrig", Types.INTEGER),
new SqlParameter("nPBulCsysIdDest", Types.INTEGER),
new SqlParameter("nPBulCsysIdOcc", Types.INTEGER),
new SqlParameter("dPPcsEventLt", OracleTypes.TIMESTAMP),
new SqlParameter("sPMsgBarcodeTypCd", Types.VARCHAR),
new SqlParameter("sPMsgBarcodeValTx", Types.VARCHAR),
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("sPMsgTx", ConsignmentMatchingHelper.linearizeXml(msg));
map.put("sPConLegacyId", shipmentMatch.getShipmentDetail().getConLegacyNr().trim());
map.put("nPConId", null);
map.put("nPPceNr",
(shipmentMatch.getShipmentDetail().getPieceNr() != null)
? shipmentMatch.getShipmentDetail().getPieceNr().trim()
: null);
map.put("nPBulCsysIdCorig",
(shipmentMatch.getShipmentDetail().getCsEntryBL() != null)
? shipmentMatch.getShipmentDetail().getCsEntryBL().trim()
: null);
map.put("nPBulCsysIdOrig", null);
map.put("nPBulCsysIdDest",
(shipmentMatch.getShipmentDetail().getCsRecBL() != null)
? shipmentMatch.getShipmentDetail().getCsRecBL().trim()
: null);
map.put("nPBulCsysIdOcc",
(shipmentMatch.getShipmentDetail().getCsEventBL() != null)
? shipmentMatch.getShipmentDetail().getCsEventBL().trim()
: null);
map.put("dPPcsEventLt", ConsignmentMatchingHelper
.covertToTimestamp(shipmentMatch.getShipmentDetail().getEventDate().getLocal()));
map.put("sPMsgBarcodeTypCd",
(shipmentMatch.getShipmentDetail().getBarCdType() != null)
? shipmentMatch.getShipmentDetail().getBarCdType().trim()
: null);
map.put("sPMsgBarcodeValTx",
(shipmentMatch.getShipmentDetail().getBarCdValue() != null)
? shipmentMatch.getShipmentDetail().getBarCdValue().trim()
: null);
call.execute(map);
org.springframework.jdbc.support.MetaDataAccessException是在调用execute方法时