当我尝试使用 javax.sql.DataSource 从基于 spring 的应用程序执行存储过程时,我收到“非法参数异常”
堆栈跟踪如下。
Caused by: org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract java.sql.Connection javax.sql.DataSource.getConnection() throws java.sql.SQLException] on target [com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@4582a8fc]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
at $Proxy115.getConnection(Unknown Source)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
... 45 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
... 56 more
源代码如下。
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import org.apache.log4j.Logger;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.jdbc.object.StoredProcedure;
public class CERBulkUploadSP extends StoredProcedure{
private final Logger log = Logger.getLogger(this.getClass().getName());
public CERBulkUploadSP(DataSource dataSource, String storedProcName) {
// Run the Parent
super(dataSource, storedProcName);
if (log.isInfoEnabled()) {
log.info("CERA Processes Stored Procedure Name : "+ storedProcName);
}
// Declare the Parameter Details
declareParameter(new SqlParameter("THE_ARRAY", Types.ARRAY, "CER.GL_ENTRY_TYPE_ARRAY"));
declareParameter(new SqlParameter("INCIDENT_DIM_ID", Types.NUMERIC));
declareParameter(new SqlParameter("INS_USER", Types.VARCHAR));
declareParameter(new SqlOutParameter("P_STATUS", Types.VARCHAR));
// Compile the SP
compile();
}
public boolean execute(final BaseViewBean baseViewBean$Session, final long incidentDimId, final String loginUser, final String identifier) throws Exception {
boolean returnVal = false;
Map<String, Object> inParams = new HashMap<String, Object>();
log.info("Setting up the Stored Procedure Params");
inParams.put("THE_ARRAY", new SqlTypeValue() {
public void setTypeValue(PreparedStatement cs, int index, int sqlType, String typeName) throws SQLException {
Connection con = cs.getConnection();
ArrayDescriptor des = ArrayDescriptor.createDescriptor("CER.GL_ENTRY_TYPE_ARRAY", con);
ARRAY a = new ARRAY(des, con, baseViewBean$Session.getExcelRecLst().toArray());
cs.setObject(1, (Object)a);
}
});
inParams.put("INCIDENT_DIM_ID", incidentDimId);
inParams.put("INS_USER", loginUser);
inParams.put("P_STATUS", identifier);
if (log.isDebugEnabled()) {
log.debug("Executing the CERA Stored Procedure ");
}
Map out = execute(inParams);
log.info("output size is --------------------->>>>>>>>>> "+out.size());
for(Object o : out.keySet()){
log.info((String)out.get(o));
returnVal = Boolean.parseBoolean((String)out.get(o));
}
if (log.isDebugEnabled()) {
log.info("Output from CERA Stored Procedure :" + out);
}
return returnVal;
}
}
bean定义如下。
<bean id="cerBulkUploadSp" class="com.****.CERBulkUploadSP">
<constructor-arg index="0">
<ref bean="ceraDataSource" />
</constructor-arg>
<constructor-arg index="1">
<value>CER.GL_PROCESS_BULK_ENTRIES</value>
</constructor-arg>
</bean>
<bean id="processDao" class="com.****.ProcessDaoImpl">
<property name="storedProcedure">
<ref bean="cerBulkUploadSp"/>
</property>
<property name="hibernateTemplate" > <ref bean="ceraHibernateTemplate"/></property>
</bean>
类路径:com/*****/hibernate
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
</props>
</property>
<property name="dataSource"> <ref bean="ceraDataSource" />
</property>
</bean>
我的 JNDI 配置如下。
<bean id="ceraDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/CERDS</value>
</property>
<property name="lookupOnStartup">
<value>false</value>
</property>
<property name="cache">
<value>true</value>
</property>
<property name="proxyInterface">
<value>javax.sql.DataSource</value>
</property>
</bean>
我的类路径中的罐子如下。
JaxrpcComponent300V5.jar
ajaxtags-1.2-beta3.jar
ajaxtags-1.3-beta-rc7.jar
antlr.jar
aopalliance.jar
asm-commons.jar
asm-util.jar
asm.jar
aspectjrt.jar
aspectjweaver.jar
bsf.jar
castor-anttasks.jar
castor-codegen.jar
castor-xml.jar
cglib-nodep-2.1_3.jar
classes12.jar
commons-beanutils.jar
commons-chain.jar
commons-codec.jar
commons-collections.jar
commons-dbcp.jar
commons-digester.jar
commons-fileupload.jar
commons-httpclient.jar
commons-io.jar
commons-jxpath.jar
commons-lang.jar
commons-logging.jar
commons-pool.jar
commons-validator.jar
displaytag-1.2.jar
displaytag-export-poi-1.2.jar
displaytag-portlet-1.2.jar
dom4j-1.5.2.jar
dom4j-1.6.1.jar
ehcache.jar
ejb3-persistence.jar
hibernate-annotations.jar
hibernate-entitymanager.jar
hibernate-validator.jar
hibernate3.jar
ibatis.jar
jakarta-oro.jar
jamon.jar
javassist.jar
jaxb-api.jar
jboss-archive-browsing.jar
jericho-html-2.4.jar
jsr173_1.0_api.jar
jta.jar
juh-3.2.1.jar
juh.jar
jurt-3.2.1.jar
jurt.jar
list.txt
log4j.jar
mvel.jar
poi-3.8-20120326.jar
poi-excelant-3.8-20120326.jar
poi-ooxml-3.8-20120326.jar
poi-ooxml-schemas-3.8-20120326.jar
poi-scratchpad-3.8-20120326.jar
psecWsClient500.jar
quartz-all.jar
ridl.jar
spring-agent.jar
spring-aop.jar
spring-aspects.jar
spring-beans.jar
spring-context-support.jar
spring-context.jar
spring-core.jar
spring-jdbc.jar
spring-jms.jar
spring-mock.jar
spring-modules-validation.jar
spring-orm.jar
spring-security-acl.jar
spring-security-catalina.jar
spring-security-core-tiger.jar
spring-security-core.jar
spring-security-ntlm.jar
spring-security-openid.jar
spring-security-portlet.jar
spring-security-taglibs.jar
spring-tomcat-weaver.jar
spring-tx.jar
spring-web.jar
spring-webmvc-portlet.jar
spring-webmvc-struts.jar
spring-webmvc.jar
struts-core.jar
struts-el.jar
struts-extras.jar
struts-faces.jar
struts-scripting.jar
struts-taglib.jar
struts-tiles.jar
unoil.jar
unoloader.jar
urlprocessingfilter300V5.jar
velocity.jar
xbean.jar
xerces-2.2.1.jar
当在 tomcat 上本地运行应用程序并将数据源表示为 oracle 连接时它运行良好,但是当我将代码部署到托管我们所有应用程序的 Websphere 服务器上时,我遇到了这个问题。任何人都可以让我知道如何解决同样的问题吗?