Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for GRAILS-7789 "Pre-2.0 unit test fails when instantiating domai…

…n classes"
  • Loading branch information...
commit a6444f1a9e59888ceddc87db7490937525d3edf0 1 parent 6932eea
@graemerocher graemerocher authored
View
17 ...-controllers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllersDomainBindingApi.java
@@ -15,18 +15,15 @@
*/
package org.codehaus.groovy.grails.plugins.web.api;
-import java.util.Map;
-
-import org.codehaus.groovy.grails.commons.DomainClassArtefactHandler;
-import org.codehaus.groovy.grails.commons.GrailsApplication;
-import org.codehaus.groovy.grails.commons.GrailsDomainClass;
-import org.codehaus.groovy.grails.commons.GrailsDomainClassProperty;
-import org.codehaus.groovy.grails.commons.GrailsMetaClassUtils;
+import org.codehaus.groovy.grails.commons.*;
import org.codehaus.groovy.grails.web.binding.DataBindingLazyMetaPropertyMap;
import org.codehaus.groovy.grails.web.binding.DataBindingUtils;
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest;
+import org.springframework.context.ApplicationContext;
import org.springframework.validation.BindingResult;
+import java.util.Map;
+
/**
* Enhancements made to domain classes to for data binding.
*
@@ -95,7 +92,11 @@ private static GrailsDomainClass getDomainClass(Object instance) {
if (domainClass == null) {
GrailsWebRequest webRequest = GrailsWebRequest.lookup();
if (webRequest != null) {
- GrailsApplication grailsApplication = webRequest.getApplicationContext().getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
+ ApplicationContext applicationContext = webRequest.getApplicationContext();
+
+ GrailsApplication grailsApplication = applicationContext.containsBean(GrailsApplication.APPLICATION_ID) ?
+ applicationContext.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class) :
+ null;
if (grailsApplication != null) {
domainClass = (GrailsDomainClass) grailsApplication.getArtefact(DomainClassArtefactHandler.TYPE, instance.getClass().getName());
}
Please sign in to comment.
Something went wrong with that request. Please try again.