Ste*_*n C 5 java oracle weblogic jax-rs eclipselink
我在最新的 Weblogic 服务器版本 12.2.1.2 中观察到一个非常奇怪的行为。当 eclipselink 依赖项添加到您的 Java servlet 应用程序时,Weblogic 服务器将自动触发 /resources/* 路径下的 Jax-RS Jersey REST 服务。
为了消除任何疑问,我创建了一个非常简单的 helloworld 战争文件。可以按照此页面 ( http://geekabyte.blogspot.com/2015/07/how-to-create-war-files-with-intellij.html ) 中的说明创建示例战争文件
如果您遵循上述说明,基本上您将拥有的唯一依赖是
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并且 Helloworld 作为应用程序中唯一的类。你可以将它部署到任何服务器,它会运行得很好。
现在您将另一个依赖项添加到您的 maven pom 文件中。它是 eclipselink 工件,如下所示:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
部署 war 文件时,服务器将记录以下内容:
<May 23, 2017, 2:42:47,343 PM MST> <Warning> <JAXRSIntegration> <BEA-2192511>
<The list of resource packages: org.eclipse.persistence.jpa.rs.exceptions;org.eclipse.persistence.jpa.rs.resources;org.eclipse.persistence.jpa.rs.resources.unversioned>
Run Code Online (Sandbox Code Playgroud)
这样做的影响是,如果您遵循约定并将所有 javascript 和 css 文件存储在 /resources/ 路径下,而不是提供这些静态文件,服务器将尝试通过 JAX-RS 服务处理这些请求,最终返回 404未找到。
我尝试了不同的配置:不同的服务器、不同版本的 Weblogic 服务器、Toplink 代替 eclipselink、不同版本的 eclipselink 以及一堆其他的东西,为了简单起见,我不会在这里提及。显然,我们有一个运行在先前版本的 Weblogic 中的工作应用程序,我们需要将其迁移到最新版本的 Weblogic。花了很多天来查明这个依赖项的问题。在任何情况下,这个问题只存在于 Weblogic 12.2.* 以任何版本的 eclipselink 作为依赖项。
我对每个人的明显问题是:为什么会发生这种情况?有没有人遇到过同样的问题?你的解决方案是什么?
只是为了澄清我的错误和解决方案,我在 Weblogic 12.2.1.2 中没有此错误(/resources/* 路径),但在 12.2.1.3 中确实有此错误,并且在我的组织获得后我注意到这个新路径 /resources/*它升级了(到12.2.1.3)。
由于我的war中包含了eclipselink.jar,所以我尝试了“oracode”的建议,所以我在POM中指定了“提供”的范围,然后我构建了新的war,但它并没有影响结果。我仍然遇到问题。
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
然而,对我有用的解决方案是:在我的 web.xml 中添加 init-param 部分。
在我的组织中,我们有 N 个 Web 服务,所以我开始比较它们,我注意到其中一项服务(因 /resources/* 失败的服务)没有明确指定 init-param 部分,所以我添加了它我的网络服务现在在 /* 下工作正常。
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.xxxxxx.xxx.xxx.xxx</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2892 次 |
| 最近记录: |