【问题标题】:Grails errors in connecting to sms plugin连接到短信插件时出现 Grails 错误
【发布时间】:2015-10-15 23:12:41
【问题描述】:

前两个文件是“SmsController.groovy”和“applicationContext.xml”,我认为它们会导致错误。

'SmsController.groovy':

package nexmo

import grails.plugin.nexmo.NexmoException

class SmsControllerController {

// Inject the service
def nexmoService
def smsResult

def index() {

    try {
        // Send the message "What's up?" to 1-500-123-4567

        smsResult = nexmoService.sendSms("61451062006", "What's up?")
    }

        catch (NexmoException e) {
            // Handle error if failure
        }
    }
}

'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" />
</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="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" />

以下是我从新应用复制文件后遇到的错误。 (applicationContext.xml、sitemesh.xml 和一些 .tld 文件):

context.ContextLoader Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; ne
sted exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: nexmo.SmsController
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: nexmo.SmsController
    ... 4 more
Caused by: java.lang.ClassNotFoundException: nexmo.SmsController
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    ... 4 more
context.GrailsContextLoaderListener Error initializing the application: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init me
thod failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: nexmo.SmsController
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; ne
sted exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: nexmo.SmsController
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
 Caused by: org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: nexmo.SmsController
    ... 4 more
Caused by: java.lang.ClassNotFoundException: nexmo.SmsController
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    ... 4 more
| Error Forked Grails VM exited with error

【问题讨论】:

    标签: grails plugins nexmo


    【解决方案1】:

    这可能是由于包和文件所在目录不匹配。如果控制器在grails-app/controllers/nexmo/SmsController.groovy,则需要相应的包声明:

    package nexmo
    
    class SmsController {
       ...
    }
    

    【讨论】:

    • 我可以访问“localhost:8080/nexmo”。但是,它显示如下:HTTP Status 404 - "/WEB-INF/grails-app/views/index.gsp" not found.
    • 这就像一个洋葱,你剥下的每一层都会在下面露出更多。 grails-app/views/index.gsp 存在吗?如果没有,请创建它。像以前一样,您可以通过使用相同版本的 Grails 创建一个新应用程序并从那里复制它来获取为新应用程序创建的默认文件。我假设您将继续遇到这样的问题,因为看起来很多重要文件已被删除。您可能应该创建一个新应用并将与 Nexmo 相关的代码和文件复制到其中,而不是一次修复所有这些人为问题。
    • 没有 index.gsp 所以我把它放在那里。之后,我也把index.gsp放到了sms/index.gsp中。它再次显示:'HTTP Status 404 - "/WEB-INF/grails-app/views/sms/index.gsp" not found.'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 1970-01-01
    • 2020-08-22
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    相关资源
    最近更新 更多