当我尝试在SpringToolSuite中调试时。它有时会引发异常
Invalid XmlElementRef on property expression on class org.opengeoportal.ogc.wmc.jaxb.UpperBoundaryType. Referenced Element not declared.
异常。 但有趣的是,其他时候调试效果很好。我在网上看过,有些人认为这可能是图书馆冲突。那可能吗?如果是,我应该如何追踪问题?
错误消息:
2014-11-05 14:48:31 Jaxb2Marshaller [INFO] Creating JAXBContext with classes to be bound [class org.opengeoportal.ogc.wmc.jaxb.ViewContextType]
2014-11-05 14:48:31 ThreadPoolTaskExecutor [INFO] Shutting down ExecutorService
2014-11-05 14:48:31 ContextLoader [ERROR] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'marshaller': Invocation of init method failed; nested exception is org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException:
Exception Description: Invalid XmlElementRef on property expression on class org.opengeoportal.ogc.wmc.jaxb.UpperBoundaryType. Referenced Element not declared.
- with linked exception:
[Exception [EclipseLink-50006] (Eclipse Persistence Services - 2.5.2.v20131113-a7346c6): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Invalid XmlElementRef on property expression on class org.opengeoportal.ogc.wmc.jaxb.UpperBoundaryType. Referenced Element not declared.]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
我在UpperBoundaryType.java中的@XmlElementRef public class UpperBoundaryType {
@XmlElementRef(name = "expression", namespace = "http://www.opengis.net/ogc", type = JAXBElement.class)
protected JAXBElement<?> expression;
/**
* Gets the value of the expression property.
*
* @return
* possible object is
* {@link JAXBElement }{@code <}{@link PropertyNameType }{@code >}
* {@link JAXBElement }{@code <}{@link LiteralType }{@code >}
* {@link JAXBElement }{@code <}{@link BinaryOperatorType }{@code >}
* {@link JAXBElement }{@code <}{@link BinaryOperatorType }{@code >}
* {@link JAXBElement }{@code <}{@link BinaryOperatorType }{@code >}
* {@link JAXBElement }{@code <}{@link ExpressionType }{@code >}
* {@link JAXBElement }{@code <}{@link BinaryOperatorType }{@code >}
* {@link JAXBElement }{@code <}{@link FunctionType }{@code >}
*
*/
public JAXBElement<?> getExpression() {
return expression;
}
/**
* Sets the value of the expression property.
*
* @param value
* allowed object is
* {@link JAXBElement }{@code <}{@link PropertyNameType }{@code >}
* {@link JAXBElement }{@code <}{@link LiteralType }{@code >}
* {@link JAXBElement }{@code <}{@link BinaryOperatorType }{@code >}
* {@link JAXBElement }{@code <}{@link BinaryOperatorType }{@code >}
* {@link JAXBElement }{@code <}{@link BinaryOperatorType }{@code >}
* {@link JAXBElement }{@code <}{@link ExpressionType }{@code >}
* {@link JAXBElement }{@code <}{@link BinaryOperatorType }{@code >}
* {@link JAXBElement }{@code <}{@link FunctionType }{@code >}
*
*/
public void setExpression(JAXBElement<?> value) {
this.expression = ((JAXBElement<?> ) value);
}}
My ObjectFactory文件定义表达式
@XmlElementDecl(namespace = "http://www.opengis.net/ogc", name = "expression")
public JAXBElement<ExpressionType> createExpression(ExpressionType value) {
return new JAXBElement<ExpressionType>(_Expression_QNAME, ExpressionType.class, null, value);
}
在@XmlRegistry注释的类中
环境: STS 3.6.2 JavaSE 1.7
原始答案: 在我提出问题后立即发现!这可能是由于JDK版本不兼容:@XMLElementRef文件是使用JDK 6中的vJAXB 2.1.10创建的,但是我的项目的Java编译器是7.将编译器更改为6并且它可以工作!
我曾经以为我找到了解决方案:不兼容的JDK版本。但它实际上并不是......在我将JDK更改为1.6之后,构建会多次传递,但之后调试仍然失败......
答案 0 :(得分:1)
找到解决方案!
根据this post:删除Java Servlet中的work /和temp /目录可以解决问题。但我仍然不明白为什么......有什么想法吗?
修改强>: 上述解决方案可能只是暂时的解决方案。该错误实际上是我以前忽略的bean定义文件中的语法错误...修复之后,一切都正确!
2015年5月5日更新
这结果是IDE依赖的问题。此问题仅发生在Eclipse / SST中。当我使用IntelliJ(完整版)时,这个问题就消失了。
艾伦
答案 1 :(得分:0)
对我来说,由于抽象类型而出现错误。所以我有一个Condition XmlElement和Condition是抽象的,我必须添加像@XmlSeeAlso({LevelCondition.class,SomeOtherCondition.class,...})之类的父类,以便它知道所有具体类型。