This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes Cannot find the declaration of element 'beans' -- application context invalid? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Cannot find the declaration of element Watch "Cannot find the declaration of element New topic
Author

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

Dan King
Ranch Hand

Joined: Mar 18, 2009
Posts: 84
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

That looks fine, so it must be inside the <beans> tags, so what is the "..." stuff look like?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Dan King
Ranch Hand

Joined: Mar 18, 2009
Posts: 84
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Mar 18, 2009
Posts: 84
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Mar 18, 2009
Posts: 84
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot find the declaration of element 'beans' -- application context invalid?
 
Similar Threads
AOP Not working with Spring 3 MVC application
applicationContext.xml - Can not find definition for element 'beans'
Spring AOP TX management error...
XML name space error in Spring data JPA hibernate applicationContext.xml
Adding spring-security-core-3.0.5 to org.springframework.core-3.0.0.M3