创建名称为' grailsApplication'的bean时出错

时间:2014-04-23 08:41:06

标签: grails

Grails v2.3.7

启动Grails应用程序时出现以下错误:

Error creating bean with name 'grailsApplication' defined in ServletContext

Stacktrace

Error |
    2014-04-23 13:51:13,856 [localhost-startStop-1] ERROR context.ContextLoader  - Context initialization failed
    Message: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: conf.ApplicationResources
        Line | Method
    ->>  262 | run       in java.util.concurrent.FutureTask
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    744 | run       in java.lang.Thread
    Caused by GrailsConfigurationException: Class not found loading Grails application: conf.ApplicationResources
    ->>  262 | run       in java.util.concurrent.FutureTask
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    744 | run       in java.lang.Thread
    Caused by ClassNotFoundException: conf.ApplicationResources
    ->>  366 | run       in java.net.URLClassLoader$1
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |    355 | run       in     ''
    |    354 | findClass in java.net.URLClassLoader
    |    425 | loadClass in java.lang.ClassLoader
    |    262 | run . . . in java.util.concurrent.FutureTask
    |   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    744 | run       in java.lang.Thread
    Error |
    2014-04-23 13:51:14,606 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: conf.ApplicationResources
    Message: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: conf.ApplicationResources
        Line | Method
    ->>  262 | run       in java.util.concurrent.FutureTask
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    744 | run       in java.lang.Thread
    Caused by GrailsConfigurationException: Class not found loading Grails application: conf.ApplicationResources
    ->>  262 | run       in java.util.concurrent.FutureTask
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    744 | run       in java.lang.Thread
    Caused by ClassNotFoundException: conf.ApplicationResources
    ->>  366 | run       in java.net.URLClassLoader$1
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |    355 | run       in     ''
    |    354 | findClass in java.net.URLClassLoader
    |    425 | loadClass in java.lang.ClassLoader
    |    262 | run . . . in java.util.concurrent.FutureTask
    |   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    744 | run       in java.lang.Thread
    Error |
Forked Grails VM exited with error

的applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
        <description>Grails application factory bean</description>
        <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
        <property name="grailsResourceLoader" ref="grailsResourceLoader" />
    </bean>

    <bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
        <description>A bean that manages Grails plugins</description>
        <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
        <property name="application" ref="grailsApplication" />
    </bean>

    <bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
        <constructor-arg>
            <ref bean="grailsApplication" />
        </constructor-arg>
        <property name="pluginManager" ref="pluginManager" />
    </bean>

    <bean id="grailsResourceLoader" class="org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean" />

    <bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
        <property name="encoding">
            <value>utf-8</value>
        </property>
    </bean>

    <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean" />
</beans>

4 个答案:

答案 0 :(得分:0)

请完整检查控制器名称,控制器内部使用的软件包名称是否有拼写错误。

  

特别是控制器。

答案 1 :(得分:0)

Grails ApplicationContext.xml grailsResourceLoader

重复

https://groups.google.com/forum/#!forum/grails-dev-discuss

(将2.4发行版中的applicationContext.xml复制到您的 grails app)

答案 2 :(得分:0)

当我删除了我的域类中的某个包目录时,我也发现了相同的异常 - &gt;未找到类加载Grails应用程序

Exception的原因是在某个文件中导入了错误的包。

答案 3 :(得分:0)

创建一个简单的Gradle项目。 打开build.gradle文件。 确保Gradle,Grails和Groovy插件版本彼此兼容。 从Gradle-Grails插件网站复制build.gradle示例的内容,并将其粘贴到IDE中打开的构建文件中。 在Gradle工具窗口中,单击刷新图标以刷新Gradle项目。 Grails任务列表将添加到Gradle Tool窗口的All tasks区域。 从“所有任务”列表中,运行init任务。 该任务创建Grails应用程序。 Grails View工具窗口可用,您可以开始使用Grails。 有关使用Grails的更多信息,请参阅Grails过程。

https://www.jetbrains.com/idea/help/creating-gradle-project-with-grails-integration.html