Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot find the declaration of element 'beans' -- application context invalid?

 
Dan King
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When trying to load the application context I get the following error:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from class path resource [applicationContext-persistence.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.


Below is the beans declaration. Oddly, the error is always on line 11, regardless of which namespace-location pair is on the line. I'm using 3.0.2.RELEASE and maven to manage the dependencies; I've checked that the jars are in maven's local repository. Anyone know how to resolve this?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks fine, so it must be inside the <beans> tags, so what is the "..." stuff look like?

Mark
 
Dan King
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:That looks fine, so it must be inside the <beans> tags, so what is the "..." stuff look like?

Mark




database.persistence file:
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, that all looks very clean. Great job on that configuration file, very easy to read.

OK, I once had an issue, not sure if it was the same as your, where I used STS/Eclipse IDE with Spring plugins and used the check boxes when creating the Spring Configuration file, and also using the Namespace tab at the bottom of the xml document in the IDE, and added or removed namespaces.

I saw that the IDE wouldn't have each value in xsi:schemaLocation on a separate line (I like it on separate lines like you have) they would have it scroll more to the right. And when I added carriage returns, then went back to add or remove a namespace that it wouldn't work.

If you are using Eclipse or STS Eclipse, try removing all the namespaces manually, then click on the namespace tab at the bottom and re-add them, keeping them in the long single line that it creates and see if you still get the error.

Good Luck

Mark
 
Dan King
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:Again, that all looks very clean...

Mark


I found the error, it's on line 7 of the above posted app context, xmlns:xsi="htp://www.w3.org/2001/XMLSchema-instance"
However, once I fixed that I received the error message:
java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence


Surprisingly, the issue was that I hadn't retrieved hibernate's implementations of JPA 2.0. I was under the impression that spring-orm contained the hibernate implementation jars of JPA 2.0. Can you recommend any documents and/or other resources that I can use to clarify what is needed in order to implement JPA 2.0 via Hibernate? Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is Hibernate's Maven Repository for the latest version of Hibernate 3.5.1 which implements JPA 2.0

http://repository.jboss.org/maven2/org/hibernate/

You just need Hibernate's jar files in your classpath.

Mark
 
Dan King
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:
You just need Hibernate's jar files in your classpath.
Mark


Thanks for the clarification; I was worried I missed some bigger component/concept.

Prior to my previous post @ 5:43pm, I added JBoss' repo to my pom and subsequently hibernate-entitymanager (and the transitive jars), which resolved the remaining issue.
 
Manoj Kumar abc
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on migration project from websphere to jboss 6.3 eap. When i deploy my application on jboss, i am getting Parser exception as below:


18:41:51,567 ERROR [com.silvermoongroup.was.startup.ejb.EagerClassLoaderBean]
(ServerService Thread Pool -- 77) Error when initialising class: Unable to return
specified BeanFactory instance:
factory key [com.silvermoongroup.common], from group with resource name
[classpath:com/churchmutual/ocns/common/beanRefContext.xml];
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'com.silvermoongroup.common' defined in class path resource
[com/churchmutual/ocns/common/beanRefContext.xml]: Instantiation of bean failed;
nested exception is org.springframework.beans.BeanInstantiationException: Could
not instantiate bean class
[org.springframework.context.support.ClassPathXmlApplicationContext]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 37
in XML document from class path resource [com/silvermoongroup/base/tx/jee-
transaction-context.xml] is invalid; nested exception is
org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 82; cvc-elt.1:
Cannot find the declaration of element 'beans'.:
org.springframework.beans.factory.access.BootstrapException: Unable to return
specified BeanFactory instance: factory key [com.silvermoongroup.common], from
group with resource name
[classpath:com/churchmutual/ocns/common/beanRefContext.xml]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'com.silvermoongroup.common' defined in class path resource
[com/churchmutual/ocns/common/beanRefContext.xml]: Instantiation of bean failed;
nested exception is org.springframework.beans.BeanInstantiationException: Could
not instantiate bean class
[org.springframework.context.support.ClassPathXmlApplicationContext]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 37
in XML document from class path resource [com/silvermoongroup/base/tx/jee-
transaction-context.xml] is invalid; nested exception is
org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 82; cvc-elt.1:
Cannot find the declaration of element 'beans'.


So i changed beans xmlns to DTD like this:


<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


to


<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">


and it worked fine, there is no parsing exception as such.
But in one xml having transaction configuration like this:


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">


when i changed it to above mentioned DTD, it throwing exception.
org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 15; Document root element "tx:transaction", must match DOCTYPE root "beans".

Please help me to resolve this issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic