运行时保留策略Java批注在Weblogic 12C中不起作用 [英] RunTime Retention policy java annotations doesn't work in Weblogic 12C

查看:90
本文介绍了运行时保留策略Java批注在Weblogic 12C中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们计划将产品升级到Web-logic 12.C和WebSphere 8堆栈(之前是WLC 10.3.5和WAS 7)。但是,导致整个应用程序无法在Web逻辑中部署的Web服务组件之一的问题。它与WebSphere 8完美配合。



在部署EAR时,应用程序服务器抛出'Exception [EclipseLink-59](Eclipse Persistence Services-2.3.2.v20111125-r10461 ):org.eclipse.persistence.exceptions.DescriptorException'。经过更多分析之后,我发现了导致问题的WebServce依赖类之一中的以下代码,

  @ExcludeAttribute 
public Map getOperations(){
Map map = new HashMap();
//一些操作
返回图;
}

@ExcludeAttribute描述运行时保留策略,其定义如下所示

  @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ExcludeAttribute {
}

getOperations 方法返回java .util.Map不适用于RunTime保留批注,但适用于任何其他数据类型,例如(Integer,Customer等)。我已更改为java.uitl.HashMap,但无法正常工作。



我能够通过使用以下注释来解决此问题(宁可称之为解决方法),


@XmlTransient


我没有其他线索为什么它不能与java.uitl.Map一起使用。任何想法都会让我竖起大拇指!!我已经发布了对Oracle的支持,即使他们还没有回来。结合使用WEblogic12c / Annotations的java.util.Map/Collection类是否存在任何已知问题。





要回答Doughan问题,返回非集合数据类型的方法不会引发任何异常,例如:

  @ExcludeAttribute 
public Integer getOperations(){
返回1;
}

其中@ExcludeAttribute是自定义注释定义了'@Retention(RetentionPolicy.RUNTIME)' ,并且我不需要定义@XmlTransient来忽略它。

我对使用保留运行时批注感到有些困惑,并且不确定是否需要保留它或应该使用XMLTransient批注。




我知道我们需要如果不从Weblogic 12C映射getter方法(作为@XMLTransient),则显式地对其进行注释,这与RuntTime Retention注释无关。因此,如果存在未映射的公共获取方法,则任何升级到12C的堆栈都应使用此注释更新代码库。我认为这几乎可以回答我的担忧。



如果我错了,请纠正我。



现有代码库已经使用运行时注释进行了注释,我



详细的堆栈跟踪如下


weblogic。 application.ModuleException:[HTTP:101216] Servlet:
com.chordiant.component.cxradecisions.decision.impl.internal.AssessmentDecisionInterfaceWebServiceWrapper
无法在Web应用程序 / ra中启动时预加载。



com.sun.xml.ws.spi.db.DatabindingException:描述符异常:



Exception [EclipseLink -59](Eclipse Persistence Services-
2.3.2.v20111125-r10461):org.eclipse.persistence.exceptions.DescriptorException异常
描述:实例变量[responseButtons]在$ b $中未定义b域类[com.chordiant.dm.ra.bean.Assessment],或者
无法访问。内部异常:java.lang.NoSuchFieldException:
responseButtons映射:
org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping [responseButtons]
描述符:XMLDescriptor(com.chordiant.dm.ra。 bean.Assessment-> [])



运行时异常:



  com.sun.xml.ws.db.toplink.JAXBContextFactory.newContext(JAXBContextFactory.java:185)上的
com.sun.xml.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:179 )
在com.sun.xml.ws.model.AbstractSEIModelImpl $ 1.run(AbstractSEIModelImpl.java:211)
在com.sun.xml.ws.model.AbstractSEIModelImpl $ 1.run(AbstractSEIModelImpl.java :185)


我有一个方法getResponseButtons()在评估类

  @ExcludeAttribute 
public Map getResponseButtons(){
Map map = new HashMap();


解决方案

注意: m EclipseLink JAXB(MOXy) 的负责人和成员 JAXB(JSR-222) 专家组。



在WebLogic 12.1.1中,您需要使用 @XmlTransient 注释该属性:

  @ExcludeAttribute 
public Map getOperations(){
Map map = new HashMap();
//一些操作
返回图;
}




@ExcludeAttribute是我们创建的自定义注释,使用
@Retention(RetentionPolicy.RUNTIME),(我提供了此
批注的片段)


自定义注释不会影响MOXy如何生成其映射元数据。无法做到这一点,只是因为注释称为 @ExcludeAttribute MOXy无法假设应该将其视为 @XmlTransient


但是其中一个Web服务组件出现问题,导致整个
应用程序无法在Web逻辑中部署。在WebSphere 8中,
可以很好地工作。


EclipseLink MOXy是WebLogic自12.1.1版以来的默认JAXB提供程序。 。您可能遇到了一个问题,即以前MOXy仅使用 get 方法将所有属性视为只写属性。除非明确注释,否则新版本的MOXy将忽略这些属性。这可能会导致您觉得 @ExcludeAttribute 注释正在起作用。


我对保留时间运行注释的使用感到困惑


此设置与您是否可以访问有关在运行时通过反射进行注释。您是在为自己的目的创建自己的注释吗?


在部署EAR时,应用程序服务器会抛出'Exception
[EclipseLink- 59](Eclipse Persistence Services-
2.3.2.v20111125-r10461):org.eclipse.persistence.exceptions.DescriptorException'


如果要映射该属性的内容,您可以共享完整的堆栈跟踪吗?


We are planning to upgrade our product to Web-logic 12.C and WebSphere 8 stack ( Earlier it was WLC 10.3.5 and WAS 7). But issue in one of the web service component causing entire application failed to deploy in web logic. It works perfectly fine with WebSphere 8.

When deploying the EAR, Application sever throws 'Exception [EclipseLink-59] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DescriptorException' . After more analysis, I found below code in one of the WebServce dependant class causing the problem,

@ExcludeAttribute
public Map getOperations(){
    Map map = new HashMap();
    //some operation
    return map;
}

@ExcludeAttribute describes Runtime retention policies, which is defined as shown below

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ExcludeAttribute {
}

getOperations method returns java.util.Map which does not work with RunTime retention annotations, but works with any other data types such as (Integer, Customer etc) . I have changed to java.uitl.HashMap and did not work.

I was able to fix this (rather I would call work around) by using following annotation,

@XmlTransient

I have no other clue why does it not working with java.uitl.Map. Any thoughts would really give thumbs up!! I have posted to Oracle support, even they have not came back yet. Is there any know issues with java.util.Map/Collection class with combination of WEblogic12c/Annotations.

[EDIT - 1]

To answer Doughan question, methods which return non collection data type does not throw any exception, for eg:

@ExcludeAttribute
public Integer getOperations(){
  return 1;
}

Where @ExcludeAttribute is custom annotation defines '@Retention(RetentionPolicy.RUNTIME)', and I do not need to define @XmlTransient to ignore.
I am bit confused to with usage of retention run time annotation , and not sure if I need to keep it or should use XMLTransient annotation.

[Edit 2 ,Based on @Doughan's answer]

I understand that we need to explicitly annotate getter methods ( as @XMLTransient) if they are not to be mapped from Weblogic 12C, and this is no way related to RuntTime Retention annotations. So any stack upgrade to 12C should update code base with this annotation if there unmapped public getter methods. I think is pretty much answers my concerns.

Correct me if I am wrong.

The existing code base already has annotated with Runtime annotation, and I thought its the one causing issue.

Detailed stack trace follows

weblogic.application.ModuleException: [HTTP:101216]Servlet: "com.chordiant.component.cxradecisions.decision.impl.internal.AssessmentDecisionInterfaceWebServiceWrapper" failed to preload on startup in Web application: "/ra".

com.sun.xml.ws.spi.db.DatabindingException: Descriptor Exceptions:

Exception [EclipseLink-59] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DescriptorException Exception Description: The instance variable [responseButtons] is not defined in the domain class [com.chordiant.dm.ra.bean.Assessment], or it is not accessible. Internal Exception: java.lang.NoSuchFieldException: responseButtons Mapping: org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping[responseButtons] Descriptor: XMLDescriptor(com.chordiant.dm.ra.bean.Assessment --> [])

Runtime Exceptions:

            at com.sun.xml.ws.db.toplink.JAXBContextFactory.newContext(JAXBContextFactory.java:185)
            at com.sun.xml.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:179)
            at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:211)
            at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:185)

And I have a method getResponseButtons() defined in Assessment class

@ExcludeAttribute
    public Map getResponseButtons() {
        Map map = new HashMap();

解决方案

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

In WebLogic 12.1.1 you will need to annotate that property with @XmlTransient:

@ExcludeAttribute
public Map getOperations(){
    Map map = new HashMap();
    //some operation
    return map;
}

@ExcludeAttribute is custom annotation created by us, which uses @Retention(RetentionPolicy.RUNTIME), ( I have provided snippet of this annotation)

Custom annotations do not affect how MOXy produces its mapping metadata. There is no way that it could, just because the annotation is called @ExcludeAttribute MOXy couldn't assume it should be treated like @XmlTransient.

But issue in one of the web service component causing entire application failed to deploy in web logic. It works perfectly fine with WebSphere 8.

EclipseLink MOXy is the default JAXB provider in WebLogic as of version 12.1.1. You may be hitting an issue where previously MOXy treated all properties with only a getmethod as write only properties. New versions of MOXy will ignore these properties unless they are explicitly annotated. This may have caused it to appear to you that the @ExcludeAttribute annotation was having an effect.

I am bit confused to with usage of retention run time annotation

This setting is related to whether or not you can access this annotation via reflection at runtime. Are you creating your own annotation for your own purposes?

When deploying the EAR, Application sever throws 'Exception [EclipseLink-59] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DescriptorException'

If the contents of that property are meant to be mapped could you share the complete stack trace?

这篇关于运行时保留策略Java批注在Weblogic 12C中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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