code: public static GrailsApplication lookupApplication(ServletContext servletContext) {
          if (servletContext == null) {
              return null;
          }
  
          GrailsApplication grailsApplication = (GrailsApplication)servletContext.getAttribute(ApplicationAttributes.APPLICATION);
          if(grailsApplication != null) {
              return grailsApplication;
          }
  
          final WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
          if (context == null || !context.containsBean(GrailsApplication.APPLICATION_ID)) {
              return null;
          }
  
          return context.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
      }
docs: Looks up a GrailsApplication instance from the ServletContext.
  
  @param servletContext The ServletContext
  @return A GrailsApplication or null if there isn't one