java.lang.ClassNotFoundException:com.ibm.ws.rsadapter.jdbc.WSJdbcConnection

时间:2015-04-21 09:14:30

标签: jdbc websphere-liberty

我正在尝试使用eclipse Luna的WAS自由rutime配置文件。

我的环境:

  
      
  • Window 7
  •   
  • Eclipse luna
  •   
  • Websphere应用服务器工具V8.5插件
  •   
  • Websphere liberty profile
  •   

我的应用程序使用spring framework 2.5,配置文件如下。

<!-- For Oracle and Websphere; you need to use this lob handler definition instead of defaultLobHandler. Because of differences in Oracle's Blob objects. -->
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" >
    <property name="nativeJdbcExtractor" >
        <bean class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor"/>
    </property>
</bean>

然而,当我将我的应用程序部署到Liberty Profile(LP)时。由于某种原因,该课程无法正确加载。

我可以在com.ibm.ws.jdbc_1.0.8.jar文件中找到这个类,这个jar文件位于{server.home} / lib文件夹下。据我所知,这个库应该自动加载。

错误日志的详细信息:

[ERROR   ] SRVE0283E: Exception caught while initializing context: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oracleLobHandler' defined in ServletContext resource [/WEB-INF/dataAccessContext.xml]: Cannot create inner bean 'org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor#fff379a3' of type [org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor] while setting bean property 'nativeJdbcExtractor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor#fff379a3' defined in ServletContext resource [/WEB-INF/dataAccessContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize WebSphereNativeJdbcExtractor because WebSphere API classes are not available: java.lang.ClassNotFoundException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:282)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:121)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1391)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2388)
    at [internal classes]
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize WebSphereNativeJdbcExtractor because WebSphere API classes are not available: java.lang.ClassNotFoundException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004)
    ... 21 more
Caused by: java.lang.IllegalStateException: Could not initialize WebSphereNativeJdbcExtractor because WebSphere API classes are not available: java.lang.ClassNotFoundException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
    at org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor.<init>(WebSphereNativeJdbcExtractor.java:65)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:56)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)

关于这个问题的任何想法都非常感谢。我真的很痛苦。

非常感谢提前。

3 个答案:

答案 0 :(得分:2)

com.ibm.ws.jdbc_1.0.8.jar是OSGi包,您引用的包不会被导出,因此它不适用于应用程序类。

我认为您需要这样才能获得本机连接,因为您有两种选择:

  • 使用JDBC API unwrap()方法,例如connection.unwrap()。请参阅一些连接示例和prepareStatement here
  • 更新到Spring 3.0.5或更高版本并使用OracleJdbc4NativeJdbcExtractor代替WebSphereNativeJdbcExtractor(我没有对此进行测试,但理论上应该有效)。

答案 1 :(得分:1)

您是否在server.xml中启用了jdbc功能?如果您有最近的Liberty安装,我建议启用webProfile-6.0功能,该功能是许多常用功能的组合。

答案 2 :(得分:1)

变化: class =“org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor”/&gt;

于: class =“org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor”/&gt;