gpt4 book ai didi

grails - 连接SMS插件时出现Grails错误

转载 作者:行者123 更新时间:2023-12-02 14:41:30 25 4
gpt4 key购买 nike

前两个文件是“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

最佳答案

这可能是由于软件包与文件所在目录之间的不匹配所致。如果 Controller 位于grails-app/controllers/nexmo/SmsController.groovy中,则需要相应的package语句:

package nexmo

class SmsController {
...
}

关于grails - 连接SMS插件时出现Grails错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33160028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com