I’ve been having the weirdest issue with Grails 2.0M1 (nee 1.4M1). My application ran fine with “grails run-app”, but would fail when did a “grails tomcat deploy” and deployed to either Tomcat 6 or Tomcat 7. The error I was getting was…
ERROR initWebApplicationContext, Context initialization failed org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.IllegalStateException: Cannot locate GORM API implementation. You either don't have a GORM implementation installed (such as the Hibernate plugin) or you are running Grails code outside the context of a Grails application.
Opening up the .war file, I could tell the hibernate plugin wasn’t being included, and having a look at /WEB-INF/grails.xml there was no trace of the line that I was expecting:
<plugin>HibernateGrailsPlugin</plugin>
So… who stripped away my HibernateGrailsPlugin?!?
After much mucking about, I found the source of the problem. It was deep inside _GrailsWar.groovy. Somewhere around line 209 it filters out plugins based on their dependency tree (to make sure unnecessary testing/runtime plugins don’t live on inside your war). In particular, something in the Hibernate 1.4.0M1 plugin’s dependency graph results in the dependency.isSupportInConfiguration(it) returning “false”, and it getting stripped from the war file.
So it looks like the problem is inside the dependency tree for the Hibernate 1.4.0M1 plugin. A temporary workaround is to hack in a special case inside _GrailsWar.groovy until things are fixed up (insert the second line from the extract below below somewhere around line 209-ish of _GrailsWar.groovy)
def i = configs.any { descriptor.isSupportedInConfiguration(it) }
if (false == i && info.name == "hibernate") i = true
i != null ? i : true
Rerun “grails war” and you’ll see that the hibernate plugin gets package and your grails.xml file reflects that it’s a starter.
I’ll create up a JIRA for this on Monday when I’m back online since I’d like to include the exact steps to replicate since this only seems to affect a few people (if that’s you, I guess you’re just lucky!).
Hi Glen,
did you already post that bug? Could you please tell me the JIRA number?
I still get this error in current Grails 2.0.0 SNAPSHOT.
Thanks,
Marc
… and I can’t find the place to fix that bug in the sources of 2.0.0-SNAPSHOT
I can reproduce the issue.
If the domain class has id, and version attributes defined, it is causing the above error
Fix, is do not define ID, and version attributes
I am experiencing this as well for grails 1.3.7. But the symptom is different for me. For me, it’s NoSuchBeanDefinitionException on ‘transactionManager’
Add this does not help either:
grails.project.dependency.resolution = {
…
plugins {
runtimes “:hibernate:$grailsVersion”
}
}
May I ask where the jira ticket is for this?
Thanks,
Franz