【问题标题】:how to resolve "WebSphere API classes are not available"?如何解决“WebSphere API 类不可用”?
【发布时间】:2016-03-09 20:45:54
【问题描述】:

我安装了带有 WAS Liberty 的 Eclipse Mars,运行时尝试设置数据源。这是我得到的错误:

“无法初始化 WebSphereDataSourceAdapter,因为 WebSphere API 类不可用:java.lang.ClassNotFoundException: com.ibm.websphere.rsadapter.WSDataSource”

我的 server.xml 中有这个

<featureManager>
    <feature>javaee-7.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>jdbc-4.1</feature>
    <feature>webProfile-7.0</feature>
</featureManager>

其他 SO 引用了瘦客户端 jar 文件,但在我的 wasruntime/lib 目录和这 346 个 jar 文件中都不存在。还有其他想法吗?

这是我的春季宣言。

 <bean id="myDataSource" class="org.springframework.jdbc.datasource.WebSphereDataSourceAdapter">
   <property name="targetDataSource">
     <bean class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName" value="jdbc/db2"/>
     </bean>
   </property>
 </bean>

【问题讨论】:

    标签: java eclipse spring datasource websphere-liberty


    【解决方案1】:

    WebSphere Liberty 中不存在 com.ibm.websphere.rsadapter.WSDataSource 类。它确实存在于传统 WebSphere 中,这可能是混乱的来源。

    如果您对指定类名有任何控制权,您只需将其更新为正确的名称即可。

    如果您对此没有控制权,这听起来像是 Spring 框架的一个错误。同时,您可以通过将javax.sql.DataSource 指定为proxyInterface 属性的值来解决此问题。

    将您的 spring 声明更改为以下内容:

    <bean id="myDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jdbc/db2"/>
        <property name="proxyInterface"  value="javax.sql.DataSource" />
    </bean>
    

    (注意:我还去掉了一层不必要的嵌套配置)

    小旁注:
    您发布的功能列表中有一些额外的东西。 jdbc-4.1webProfile-7.0 功能包含在整个 javaee-7.0 功能中,因此您只需将功能管理器更改为:

    <featureManager>
        <feature>javaee-7.0</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>
    

    【讨论】:

    • 这行得通,虽然我还需要添加 aopalliance-1.0.jar 文件。
    • 有趣,你需要把额外的 jar 拉进什么类?
    • 它是 org/aopalliance/aop/Advice。我没有使用maven安装spring,我只是把罐子倒在那里,这可能是原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 2022-06-24
    • 1970-01-01
    相关资源
    最近更新 更多