java Weblogic 12c:Jersey 的 Prefer-web-inf-classes 和 preferred-application-packages

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36292980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 01:13:42  来源:igfitidea点击:

Weblogic 12c : Prefer-web-inf-classes and prefer-application-packages for Jersey

javaguiceweblogic12cjersey-1.0guice-servlet

提问by Azimuts

I have to use both (oddly enough ..) prefer-web-inf-classesand prefer-application-packagesproperties of weblogic.xmlon a Weblogic 12c Server (12.2.1)

我必须在Weblogic 12c 服务器 (12.2.1)上同时使用(奇怪的是 ..)prefer-web-inf-classesweblogic.xml 的prefer-application-packages属性

It is REST application based on Jersey 1.9. ( Jersey 1.x JAX-RS RI) and Guice.

它是基于 Jersey 1.9 的 REST 应用程序。( Jersey 1.x JAX-RS RI) 和 Guice。

1. Why use :prefer-web-inf-classes

1. 为什么使用 :prefer-web-inf-classes

If you have more than one WAR you have to place at the level of war/lib the libraries for guice-jersey / guice , other way you get an Multibindings Error.

如果您有多个 WAR,则必须将 guice-jersey / guice 的库置于 war/lib 级别,否则您会得到Multibindings Error

It must be indicated also the prefer-web-inf-classesto true.

还必须指明prefer-web-inf-classesto true

This way it works properly!

这样它就可以正常工作了!

I have tried to work in the same way using prefer-application-packages with packages (com.sun.jersey.guice.spi.container.servlet, com.google.inject.servlet, etc...) but no way.

我已经尝试使用工作以同样的方式prefer-application-packages的包(com.sun.jersey.guice.spi.container.servletcom.google.inject.servlet,等...),但没有办法。

Note: It is not possible to exclude this libraries at EARlevel.

注意:无法在EAR级别排除此库。

2. Why use :prefer-application-packages

2. 为什么使用 :prefer-application-packages

To use Jersey 1.x JAX-RS RI on Weblogic 12c (12.2.1) so I have to indicate the following packages (other way Weblogic uses Jersey 2, and different version of Hymanson libraries, etc.)

要在 Weblogic 12c (12.2.1) 上使用 Jersey 1.x JAX-RS RI,我必须指明以下包(Weblogic 使用 Jersey 2 的其他方式,以及不同版本的 Hymanson 库等

It works perfectly on Jersey 1.X if it is indicated this way.. I have probed two war separately, and works fine... but, remember my friend I have two war..so....

如果以这种方式指示,它可以在 Jersey 1.X 上完美运行. 我分别探讨了两场War,并且工作正常......但是,请记住我的朋友我有两场War......所以......

Summary

概括

I can not use both properties (deploying error for using both properties on the weblogic.xml..), but it's needed :

我不能同时使用这两个属性(在 weblogic.xml 上使用这两个属性时出现部署错误..),但它是必需的:

  1. For the problem with Guice Filter, need to put prefer-web-inf-classesto trueto use guice-servlet.jar/ jersey-guice.jarat war-lib level.
  2. To work with Jersey 1.x, need to use ..... prefer-application-package
  1. 对于吉斯过滤器,需要的问题提出prefer-web-inf-classestrue使用guice-servlet.jar/jersey-guice.jarWar-lib的水平
  2. 要使用 Jersey 1.x,需要使用 ..... prefer-application-package

Question: How to combine both to use one of them??

问题:如何将两者结合使用其中之一?

采纳答案by Azimuts

After all

毕竟

  1. Use just prefer-web-inf-classesto true.
  2. If you use this, you don't need to use prefer-application-packages....BUT ENSURE that you have the correct libraries at war /ear level.

    The problem was:

  1. prefer-web-inf-classes用于true.
  2. 如果你使用它,你不需要使用prefer-application-packages......但确保你在 war /ear 级别拥有正确的库。

    问题是:

The Project had a dependency with Jersey 2 (based on Swaggerfor Jersey 2.X ...) So via Swagger dependencies (swagger-jersey2-jaxrs), Jersey 2 libraries was packaged on ear/war... and so prefer-web-inf-classesHAS NO EFFECT!

该项目与 Jersey 2 有依赖关系(基于Swaggerfor Jersey 2.X ...)所以通过 Swagger 依赖项 ( swagger-jersey2-jaxrs),Jersey 2 库被打包在 ear/war ......所以prefer-web-inf-classes没有效果!

After removing the dependency all was resolved!

删除依赖后,一切都解决了!

At same the level (classpath or ear lib, or war lib) should not exist different versions of the same library.

在同一级别(类路径或耳库或War库)不应存在同一库的不同版本。

回答by Gajendra Singh

  • Hello, world! Hi, There are two way to resolve this problem.

    1. You can used to combine both file in to one file and call it based on choose tag as requirements.

    2. You can just write tags to merge or import/ include your xml file in to one. Example shown. Hint: Do google how to merge and call xml file based on condition.

  • 你好世界!你好,有两种方法可以解决这个问题。

    1. 您可以将两个文件合并为一个文件,并根据选择标签作为要求调用它。

    2. 您可以只编写标签来合并或导入/包含您的 xml 文件。示例显示。提示:谷歌如何根据条件合并和调用xml文件。