【问题标题】:Using Spring with WebSphere 8.5.5 and Apache Wink - ClassNotFoundException将 Spring 与 WebSphere 8.5.5 和 Apache Wink 一起使用 - ClassNotFoundException
【发布时间】:2015-07-08 15:47:21
【问题描述】:

我目前正在将使用 Wink 1.1.1 和 Spring 3.1.2 的 Java 应用程序从 WAS 7 迁移到 WAS 8.5.5。我正在尝试使用 WAS 8.5 中提供的本机 Wink 集成,而不是使用我们目前在 WAS 7 中使用的单独的 Wink jar。

我在服务器启动时遇到如下错误:

引起:java.lang.ClassNotFoundException: org.apache.wink.server.internal.registry.ResourceRegistry 在 java.net.URLClassLoader.findClass(URLClassLoader.java:434)

我对此有点困惑,因为据我所知,上面引用的类确实包含在Apache version of the wink jar 中。

然后我想我的问题围绕着 IBM 的 Wink 1.1.1 实现,该实现集成到 WAS 8.5.5 中。这个类不应该在 IBM 的实现中也可用吗?我在这里错过了什么?

这是我的 web.xml 的 sn-p,以防万一:

 <servlet>
    <servlet-name>IBM Rest Servlet</servlet-name>
    <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
  </servlet>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:META-INF/server/wink-core-context.xml
        /WEB-INF/spring/applicationContext-configuration.xml</param-value>
  </context-param>

另外,在我的战争中,我的 lib 文件夹中只有 wink-spring-support-1.1.1-incubating.jar。没有其他的眨眼罐。

这是我的 applicationContext-configuration.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">

    <context:annotation-config />

    <bean class="org.apache.wink.spring.Registrar">
        <property name="classes">
            <set value-type="java.lang.Class">
            </set>
        </property>
        <property name="instances">
            <set>
                <ref local="someResource" />
                <!-- ... -->
            </set>
        </property>
    </bean>

    <!-- Providers -->
    <bean id="jaxbProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" >
        <property name="mapper" ref="jacksonObjectMapper"/>
    </bean>

    <bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" >
        <property name="annotationIntrospector" ref="jacksonAnnotationIntrospector"></property>
    </bean>

    <bean id="jacksonAnnotationIntrospector" class="org.codehaus.jackson.map.AnnotationIntrospector$Pair" >
        <constructor-arg ref="primaryAnnotationIntrospector" />
        <constructor-arg ref="secondaryAnnotationIntrospector" />
    </bean>

    <bean id="primaryAnnotationIntrospector" class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector" />
    <bean id="secondaryAnnotationIntrospector" class="org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector" />

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
    </bean>

    <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="properties" ref="allProperties"/>
    </bean>


    <bean id="allProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
           <list>

               <value>classpath*:/META-INF/${Environment}-environment.properties</value>

           </list>
       </property>
    </bean>

    <import  resource="applicationContext-otherFile.xml"/>

</beans>

类路径上的 Spring jars

spring-jdbc-3.1.1.RELEASE.jar
spring-test-3.1.2.RELEASE.jar
spring-context-3.1.2.RELEASE.jar
spring-beans-3.1.2.RELEASE.jar
spring-core-3.1.2.RELEASE.jar
spring-tx-3.1.1.RELEASE.jar
spring-web-3.1.2.RELEASE.jar
spring-asm-3.1.2.RELEASE.jar
spring-aop-3.1.2.RELEASE.jar
spring-expression-3.1.2.RELEASE.jar

我已尝试在 EnterpriseApplications > WebAppName >> 类加载器中找到的两个类加载器设置(类加载器顺序和 WAR 类加载器策略)的所有 4 种可能组合,但结果相同。

感谢您的帮助!

【问题讨论】:

  • 你的 RestfulResource 类和 Application 子类是否被打包在了战争中?即在 //WEB-INF/classes/ 里面
  • 是的。正如预期的那样,一切都在 WEB-INF/classes 中。
  • 你能分享一下“applicationContext-configuration.xml”吗?
  • 出于测试目的,从 WAS_HOME/plugins 文件夹中复制 com.ibm.ws.prereq.jaxrs.jar 和 com.ibm.ws.prereq.jackson.jar 并将其共享库引用到您的应用程序,然后重新启动服务器。
  • 我在上面的问题中添加了 applicationContext-configuration.xml。另外,我确实有一个指向 WAS_HOME/plugins 文件夹的共享库引用。作为附加说明,我将 MyEclipse 设置为不在我的 war 文件中的 WEB-INF/lib 中包含这些 jar。你想让我在我的 WEB-INF/lib 中包含这 2 个罐子吗?

标签: java spring web.xml websphere-8 apache-wink


【解决方案1】:

在使用 websphere 期间,我曾与许多 ClassNotFoundExceptions 作斗争,根据我的经验,其中许多可以通过将 websphere 类加载器更改为 PARENT_LAST 来解决。这允许您的应用程序在 websphere 尝试加载 websphere JRE 中包含的 jars 之前加载您与应用程序一起打包的所有 jars。

【讨论】:

  • 嗯...我试过了,但后来我在服务器启动时收到此错误:com.ibm.ws.webcontainer.webapp.WebApp logError SRVE0293E: [Servlet Error]-[无法加载侦听器:org.springframework.web.context.request.RequestContextListener]:java.lang.ClassNotFoundException:类 java.lang.ClassNotFoundException:org.springframework.web.context.request.RequestContextListener at java.beans.Beans.instantiate (Beans.java:195) 不确定这是否真的让我前进了..
  • 您是使用 maven 来管理您的依赖项还是手动将 jars 添加到项目中?
  • 很遗憾,(sigh)我的公司目前不允许使用 Maven,所以我手动管理 jar。
  • 您是否尝试过使用更新版本的 wink-spring-support?此外,请验证您是否拥有该 jar 所需的所有传递依赖项。
  • 由于 IBM wink-integrated 版本使用的是 Wink 1.1.1,因此我包含了 wink-spring-support 1.1.1。如果我使用不同的版本会有负面影响吗?此外,在相关说明中,为了完整起见,我将在上面的帖子中添加我的类路径中包含的 Spring jar。但是,是的,据我所知,我已经验证了所有传递依赖项。
【解决方案2】:

我能想到的问题是“ResourceRegistry”类是从 EAR 内部的类而不是 WAR 中访问的。 Wink Classes 的范围仅限于 WAR,我的猜测是应用程序正试图从 WAR 外部访问它,这就是为什么您会收到提到的类的 ClassNotFoundException。

【讨论】:

  • 没有办法解决这个问题吗?我无法切换到 PARENT_LAST 所以我尝试了一堆不同的东西(胖战争和瘦战争与 wink-spring-support 和 spring-web 仍在战争中)但无济于事。有什么想法吗?
  • 您可以尝试将需要的jar添加为共享参考库
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-18
  • 1970-01-01
  • 2015-01-01
  • 2012-12-23
  • 2015-06-18
  • 2022-06-12
  • 1970-01-01
相关资源
最近更新 更多