2015-07-02 38 views
1

我遇到了集成测试用例在grails 3.0.2中的错误。即使只有一个简单的金丝雀集成测试。Grails3集成测试失败,出现错误

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration$GroovyMarkupConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find template location: classpath:/templates/ (please add some templates, check your Groovy configuration, or set spring.groovy.template.check-template-location=false) 
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) 
    at grails.boot.GrailsApp.run(GrailsApp.groovy:49) 
    at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:103) 
    at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68) 
    at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86) 
    ... 24 more 
Caused by: java.lang.IllegalStateException: Cannot find template location: classpath:/templates/ (please add some templates, check your Groovy configuration, or set spring.groovy.template.check-template-location=false) 
    at org.springframework.util.Assert.state(Assert.java:385) 
    at org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration$GroovyMarkupConfiguration.checkTemplateLocationExists(GroovyTemplateAutoConfiguration.java:83) 
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349) 
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300) 
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133) 
    ... 42 more 

我正在使用JDK 1.7,Groovy2.4.3和Gradle 2.3的Grails 3.0.2。

+0

您是否尝试过将spring.groovy.template.check-template-location设置为false? – lvojnovic

+0

看到这个[问题](https://github.com/grails/grails-core/issues/9038)。我尝试了建议的解决方法,但它对我无效,所以我恢复到了3.0.1。 – Ken

+0

@Ivojnovic是的,它在application.yml中。 – user1071671

回答

1

它是一个与grails 3.0.2的bug,如here所述。它将在grails 3.0.3版本中修复。直到那时,用下面的application.groovy代替你的applcation.yml。

grails { 
    profile = 'web' 
    codegen { 
     defaultPackage = 'org.grails.plugins' 
    } 
} 

info { 
    app { 
     name = '@[email protected]' 
     version = '@[email protected]' 
     grailsVersion = '@[email protected]' 
    } 
} 

spring { 
    groovy { 
     template['check-template-location'] = false 
    } 
} 

hibernate { 
    naming_strategy = 'org.hibernate.cfg.DefaultNamingStrategy' 
    cache { 
     queries = false 
    } 
} 

grails { 
    mime { 
     disable { 
      accept { 
       header { 
        userAgents = ['Gecko', 'WebKit', 'Presto', 'Trident'] 
       } 
      } 
     } 

     types { 
      all = '*/*' 
      atom = 'application/atom+xml' 
      css = 'text/css' 
      csv = 'text/csv' 
      form = 'application/x-www-form-urlencoded' 
      html = ['text/html', 'application/xhtml+xml'] 
      js = 'text/javascript' 
      json = ['application/json', 'text/json'] 
      multipartForm = 'multipart/form-data' 
      rss = 'application/rss+xml' 
      text = 'text/plain' 
      hal = ['application/hal+json', 'application/hal+xml'] 
      xml = ['text/xml', 'application/xml'] 
     } 
    } 
    urlmapping { 
     cache { 
      maxsize = 1000 
     } 
    } 
    controllers { 
     defaultScope = 'singleton' 
    } 
    converters { 
     encoding = 'UTF-8' 
    } 
    views { 
     'default' { codec = 'html' }//THIS WAS THE SOURCE OF ERROR 
     gsp { 
      encoding = 'UTF-8' 
      htmlcodec = 'xml' 
      codecs { 
       expression = 'html' 
       scriptlets = 'html' 
       taglib = 'none' 
       staticparts = 'none' 
      } 
     } 
    } 
} 

dataSource { 
    pooled = true 
    jmxExport = true 
    driverClassName = "org.h2.Driver" 
    username = "sa" 
    password = "" 
} 


// environment specific settings 
environments { 
    development { 
     dataSource { 
      dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', '' 
      url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" 
     } 
    } 
    test { 
     dataSource { 
      dbCreate = "update" 
      url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" 
     } 
    } 
    production { 
     dataSource { 
      dbCreate = "update" 
      url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" 
      properties { 
       // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation 
       jmxEnabled = true 
       initialSize = 5 
       maxActive = 50 
       minIdle = 5 
       maxIdle = 25 
       maxWait = 10000 
       maxAge = 10 * 60000 
       timeBetweenEvictionRunsMillis = 5000 
       minEvictableIdleTimeMillis = 60000 
       validationQuery = "SELECT 1" 
       validationQueryTimeout = 3 
       validationInterval = 15000 
       testOnBorrow = true 
       testWhileIdle = true 
       testOnReturn = false 
       jdbcInterceptors = "ConnectionState" 
       defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED 
      } 
     } 
    } 
} 

摘自here

相关问题