2013-01-08 61 views
0

我得到一個「非法參數異常」的應用程序時,我嘗試使用的javax.sql.DataSource從基於Spring應用程序拋出:IllegalArgumentException同時使用javax.sql.Datasource取得和託管在WebSphere

的執行存儲過程堆棧跟蹤如下。

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 [[email protected]]; 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/***** /休眠

<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> 

我的classpath中的罐子如下。

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服務器,我碰到這個問題。任何人都可以讓我知道如何解決這個問題嗎?

+0

你有沒有可能在你的類路徑上有一個ojdbc.jar? (web-inf/lib?) – abalogh

+0

@abalogh - 不,我沒有。我試圖把ojdbc14.jar,但有同樣的問題,所以我把它刪除。 – sandy

+0

@abalogh - 我用我的classpath中存在的jar列表更新了我的問題。 – sandy

回答

1

您的類路徑中包含舊的Oracle JDBC驅動程序:classes12.jar。這是爲Oracle 10.2 and JDK 1.2/1.3 - 我懷疑這是你的環境。可能還有其他JAR可能包含javax.sql.*類(不知道它們全部)。

您是否還有機會將WebSphere ClassLoader模式從PARENT_FIRST(默認值)切換到PARENT_LAST?

+0

嘗試了一切,但沒有解決方案。類加載器是PARENT_LAST。 – sandy

+0

一切?你刪除了'classes12.jar'?你用與你的環境相匹配的更新版本取而代之?你切換回PARENT_FIRST?你確定classpath中沒有其他JAR包含'javax.sql'類嗎? –

+0

這是classes12.jar的更新版本嗎?我目前使用的是Oracle 10g,我也切換到了PARENT_FIRST。它像我的Tomcat上的魅力,當我提到瘦驅動程序,但不是當我部署在使用JNDI的websphere上時。 – sandy

相關問題