2

When I try to debug in SpringToolSuite. It sometimes fired an exception

Invalid XmlElementRef on property expression on class org.opengeoportal.ogc.wmc.jaxb.UpperBoundaryType. Referenced Element not declared.

exception. But interestingly, other times the debug works well. I've looked around online and some people suggest it could be library conflicts. Is that possible? If yes, how should I track down the problem?

The error message:

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)

My @XmlElementRef in UpperBoundaryType.java 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 file defines the expression

@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);
}

in a class annotated by @XmlRegistry

Environment: STS 3.6.2 JavaSE 1.7

Original answers: Found out instantaneously after I entered my question! It's probably due to the incompatible JDK version: the @XMLElementRef file is created using vJAXB 2.1.10 in JDK 6 but my project's Java Compiler is 7. Changed the complier to 6 and it works!

I used to thought I found the solution: incompatible JDK version. But it's actually not... The build get passed through several times after I change JDK to 1.6 but after that the debug failed still...

Allen Lin
  • 1,179
  • 4
  • 13
  • 23

2 Answers2

1

Found out the solution!

According to this post: Deleting the work/ and temp/ directory in your Java Servlet does the trick. But I still don't understand why.... Any thoughts?

EDIT: The above solution might be just a temporary one. The error is actually a syntax error in my bean definition file that I used to ignored... After fixing that, everything is right!

Update 05/07/2015

This turned out to be a IDE dependent issue. This issue only happens in Eclipse/SST. When I used IntelliJ (full version), this issue is gone.

Allen

Community
  • 1
  • 1
Allen Lin
  • 1,179
  • 4
  • 13
  • 23
0

For me the error occcured because of an abstract type. So I had a Condition XmlElement and Condition was abstract and I had to add to the parent class something like @XmlSeeAlso({ LevelCondition.class, SomeOtherCondition.class, ... }), so that it knows all the concrete types.

Siderite Zackwehdex
  • 6,293
  • 3
  • 30
  • 46