添加eclipselink工件时,在Weblogic 12.2.1中自动注册Jax-RS [英] Automatic Jax-RS registration in Weblogic 12.2.1 when adding eclipselink artifact

查看:930
本文介绍了添加eclipselink工件时,在Weblogic 12.2.1中自动注册Jax-RS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在最新的Weblogic服务器版本12.2.1.2中观察到一种非常奇怪的行为。
当eclipselink依赖项添加到Java servlet应用程序时,Weblogic服务器将在/ resources / * path下自动触发Jax-RS Jersey REST服务。



为了消除任何疑虑,我创建了一个非常简单的helloworld war文件。可以按照此页面中的说明创建示例war文件(



这样做的影响是,如果您遵循约定并将所有javascript和css文件存储在/ resources /下路径,而不是提供这些静态文件,服务器将尝试通过JAX-RS服务处理这些请求,最终返回404找不到。



我尝试过不同的配置:不同的服务器,不同版本的Weblogic服务器,Toplink而不是eclipselink,不同版本的eclipselink,以及其他一些我不会在此提及以保持简单的事情。显然,我们在Weblogic的早期版本中运行了一个工作应用程序,我们需要将其迁移到最新版本的Weblogic。花了很多天才找到这个依赖的问题。在任何情况下,这个问题仅存在于Weblogic 12.2。*中,任何版本的eclipselink作为依赖。



我对每个人的明显问题是:为什么这样发生了什么?有没有人遇到过同样的问题?你的解决方案是什么?

解决方案

为了澄清我的错误和解决方案,我没有这个错误(/ Weblogic 12.2.1.2中的资源/ *路径)但是我确实在12.2.1.3中有了它,并且在我的组织升级之后我注意到了这个新的路径/资源/ *(到12.2.1.3)。



由于我的战争中包含了eclipselink.jar,我尝试了oracode的建议,所以我在POM中指定了提供的范围,然后我建立了新的战争,但它确实不影响结果。我仍然遇到问题。

 < dependency> 
< groupId> org.eclipse.persistence< / groupId>
< artifactId> eclipselink< / artifactId>
< version> 2.5.1< / version>
< scope>提供< / scope>
< / dependency>

但是,对我有用的解决方案是:在我的网站中添加init-param部分。 XML。



在我的组织中,我们有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>


I have observed a very strange behavior in the latest Weblogic server, version 12.2.1.2. When an eclipselink dependency is added to your Java servlet application, Weblogic server is going to automatically trigger Jax-RS Jersey REST service under /resources/* path.

To remove any doubts, I have created a very simple helloworld war file. A sample war file can be created by following the instruction from this page (http://geekabyte.blogspot.com/2015/07/how-to-create-war-files-with-intellij.html)

If you followed the above instruction, basically the only dependency you would have is

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

And Helloworld as the only class in the application. You can deploy this to any server and it will run just fine.

Now you add another dependency to your maven pom file. It is eclipselink artifact as you can see below:

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.2</version>
    </dependency>

When you deploy the war file, the server will log the following:

<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> 

And you will see the following from your Weblogic Admin console

The impact of this is that if you follow the convention and store all your javascript and css files under /resources/ path, instead of serving these static files, the server will try to process these requests via JAX-RS service which end up returning 404 not found.

I have tried different configurations: Different server, different version of Weblogic server, Toplink instead of eclipselink, different version of eclipselink, and a bunch of other things which I will not mention here to keep it simple. Obviously we have a working application running in prior version of Weblogic which we are needing to migrate to the latest version of Weblogic. It took many days to pinpoint the problem to this one dependency. In any case, this problem only exists for Weblogic 12.2.* with eclipselink of any version as a dependency.

My obvious question to everyone is: Why is this happening? Has anyone experienced the same issue? What was your solution?

解决方案

Just to clarify my error and solution, I did not have this error (/resources/* path) in Weblogic 12.2.1.2 but I did have it in 12.2.1.3, and I noticed this new path /resoures/* after my organization got it upgraded (to 12.2.1.3).

Since I had eclipselink.jar included in my war, I tried the suggestion from "oracode", so I specified the scope "provided" in my POM, then I build the new war, but it did not affect the result. I was still having the problem.

<dependency>
  <groupId>org.eclipse.persistence</groupId>
  <artifactId>eclipselink</artifactId>
  <version>2.5.1</version>
  <scope>provided</scope>
</dependency>

However, the solution that worked for me was: to add the init-param section in my web.xml.

In my org, we have N web services, so I started comparing them, and I noticed one of these services (the one that was failing with this /resources/*) did NOT have init-param section specified explicitly, so I added it and my web service working ok now under /*.

<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>  

这篇关于添加eclipselink工件时,在Weblogic 12.2.1中自动注册Jax-RS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆