我有一个项目,该项目连接到包含一些软件包和存储过程的Oracle DB。问题在于,当尝试从REST Web服务调用存储过程时,Spring JDBC返回错误消息。
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; SQL的未分类SQLException [{致电PKG_RECLAMO.SP_INSERTAR_RECLAMO()}]; SQL状态[90022];错误代码[90022]; Función“ SP_INSERTAR_RECLAMO” 没有禁忌 未找到功能“ SP_INSERTAR_RECLAMO”; SQL语句: 致电PKG_RECLAMO.SP_INSERTAR_RECLAMO()[90022-197]; 嵌套异常是 org.h2.jdbc.JdbcSQLException:Función“ SP_INSERTAR_RECLAMO”没有限制 找不到功能“ SP_INSERTAR_RECLAMO”; SQL语句: 致电PKG_RECLAMO.SP_INSERTAR_RECLAMO()[90022-197]
下面的几行...显示了另一条消息...
由以下原因引起: org.h2.jdbc.JdbcSQLException :函数“ SP_INSERTAR_RECLAMO” 没有禁忌 找不到功能“ SP_INSERTAR_RECLAMO”; SQL语句: 致电PKG_RECLAMO.SP_INSERTAR_RECLAMO()[90022-197] 在 org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
似乎Spring JDBC模板正在H2 DB中查找该过程,而不是使用Oracle连接器。
@Repository
public class ClsReclamoDao implements ClsIReclamoDao {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public Long insertReclamo(ClsReclamoRequestBean objRequest) {
SimpleJdbcCall jdbcCall = new
SimpleJdbcCall(jdbcTemplate).withCatalogName("PKG_RECLAMO")
.withProcedureName("SP_INSERTAR_RECLAMO");
SqlParameterSource parameterSource = new MapSqlParameterSource()
.addValue("p_nuReclamoTipoReclamo",
"123")
.addValue("p_nuAnonimo", "1")
[more parameters...]
Map<String, Object> returnMap = jdbcCall.execute(parameterSource);
...
}
这些是我的POM依赖项
<dependency>
<groupId>com.oracle</groupId>
<artifactId>oracleConnector</artifactId>
<version>7.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
有一种方法可以告诉spring总是使用Oracle Connector而不是H2 DB吗?
更新
当我尝试将SCOPE = TEST放在H2依赖项上时,就像这样...
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
应用程序在启动时失败,并显示此错误消息。
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and
no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby),
please put it on the classpath.
If you have database settings to be loaded from a
particular profile you may need to activate it
(no profiles are currently active).
更新
这是我的应用程序属性文件
spring.jmx.default-domain:appOracleService
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=userdb
spring.datasource.password=passdb
spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver
## LOGGING
logging.config=classpath:logback.xml
logging.exception-conversion-word=%wEx
logging.file.max-history=0
logging.file.max-size=10MB
logging.level.org.springframework.web=INFO
答案 0 :(得分:0)
经过大量研究,我意识到这个maven部分正在破坏所有连接内容。
<resources>
<resource>
<directory>${project.basedir}/target/generated-sources</directory>
</resource>
</resources>
我想将生成的jasper文件注册到类路径中。
但是现在,我不明白为什么这个Maven代码会破坏所有Spring JDBC内容。