简体   繁体   English

Websphere Application Server Servlet初始化错误

[英]Websphere Application Server Servlet Initialization Error

We need to migrate an app that runs on Glassfish to Websphere Application Server (WAS) 8.5.x version. 我们需要将在Glassfish上运行的应用迁移到Websphere Application Server(WAS)8.5.x版本。

To see that things are working correctly with a simple setup, I created a sample project with a single rest service. 为了看到通过简单的设置一切正常,我创建了一个带有单个rest服务的示例项目。

I did not extend javax.ws.rs.core.Application with my own class, and I only have a class with path annotations. 我没有使用自己的类扩展javax.ws.rs.core.Application,而我只有一个带有路径注释的类。 I defined a servlet in web.xml named "javax.ws.rs.core.Application" so that the annotations are scanned and services are expected to be reachable from given servlet url mapping. 我在web.xml中定义了一个名为“ javax.ws.rs.core.Application”的servlet,以便扫描注解,并且可以从给定的servlet URL映射访问服务。

When I try to access the service, I get a 404 message. 当我尝试访问该服务时,我收到一条404消息。 But the real problem is the Apache Wink that comes with standard IBM Websphere libraries. 但是真正的问题是标准IBM Websphere库附带的Apache Wink。

In the library source code (class DefaultLifecycleManager), there is a part like this: 源代码 (DefaultLifecycleManager类)中有类似以下内容的部分:

79        if (ApplicationMetadataCollector.isApplication(cls)) {
80            // by default application subclasses are singletons
81            return LifecycleManagerUtils.createSingletonObjectFactory(cls);
82        }

The isApplication(cls) method should return true, and the singleton factory for it should then be created. isApplication(cls)方法应返回true,然后应为其创建单例工厂。 However, it returns false. 但是,它返回false。 The body of the method is as following: 该方法的主体如下:

76    public static boolean More ...isApplication(Class cls) {
77        return Application.class.isAssignableFrom(cls);
78    }

I put a breakpoint there and checked the values. 我在此处放置一个断点并检查了值。 cls is exactly javax.ws.rs.core.Application, which is the same class in the 77th line. cls正是javax.ws.rs.core.Application,与第77行中的类相同。

This leads the servlet to not start correctly and return 404 to every request that maps to it. 这导致servlet无法正确启动,并向映射到它的每个请求返回404。

I don't know how this method returns false, and I need your help. 我不知道此方法如何返回false,因此需要您的帮助。

Something must be wrong with your application, maybe you have some conflicting libraries. 您的应用程序一定有问题,也许您有一些冲突的库。

I have very simple class: 我的课很简单:

@Path("/HelloRest")
public class Hello {

    @GET
    public String hello() {
        System.out.println("Rest called");
        return "Hello  " + new Date();
    }
}

with following web.xml , which is starting and working fine on WAS 8.5.5: 使用以下web.xml ,它在WAS 8.5.5上启动并正常工作:

<servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet>

<servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

when called http://localhost:9080/JAXRSTestWeb/rest/HelloRest 当被称为http://localhost:9080/JAXRSTestWeb/rest/HelloRest

如果您的应用程序中捆绑了眨眼或运动衫或任何其他jaxrs库,请将其删除。

I recently did the almost same thing when I migrate form WAS 7.0 to WAS 8.5 . 当我从WAS 7.0迁移到WAS 8.5时,我做了几乎相同的事情。 WAS 8.5 comes with inbuilt Apache Wink 1.1. WAS 8.5带有内置的Apache Wink 1.1。 You can follow these steps to migrate your application on WAS 8.5: 您可以按照以下步骤在WAS 8.5上迁移应用程序:

1) Remove all the apache wink jar from your application lib folder. 1)从您的应用程序li​​b文件夹中删除所有apache wink jar。

2) For building your application you can use these two websphere jar, com.ibm.ws.prereq.jaxrs.jar and com.ibm.ws.prereq.jackson.jar. 2)为了构建您的应用程序,可以使用这两个Websphere jar com.ibm.ws.prereq.jaxrs.jar和com.ibm.ws.prereq.jackson.jar。 you can find these jars in WAS_HOME/plugins folder. 您可以在WAS_HOME / plugins文件夹中找到这些jar。

3) Build your application with these jars but do not package these jars into your application EAR or WAR. 3)使用这些jar来构建您的应用程序,但不要将这些jar打包到应用程序EAR或WAR中。

4) If your application type is EAR then Make sure all the restful resources and the class which extends Application class are part of war. 4)如果您的应用程序类型是EAR,那么请确保所有宁静的资源和扩展Application类的类都是战争的一部分。

5) Redeploy your application, it should work fine now. 5)重新部署您的应用程序,现在应该可以正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM