gpt4 book ai didi

grails3 - 遇到错误,Spring BeanCreationException:创建名称为'validateableConstraintsEvaluator'的bean时出错

转载 作者:行者123 更新时间:2023-12-02 04:25:22 27 4
gpt4 key购买 nike

我已经将项目从grails2.5.6更新为grails3.3.9,并成功完成了单元测试。
在运行集成测试时,出现以下异常。

2019-03-07 18:26:12.169  WARN --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.spockframework.spring.SpringMockTestExecutionListener@157b7da6] to process 'before' execution of test method [public void com.mdw360.sec.UserControllerSpec.$spock_feature_0_1()] for test instance [com.mdw360.sec.UserControllerSpec@36f464d8]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'validateableConstraintsEvaluator': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException: Cannot get property 'config' on null object
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:185)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1646)

Controller
@Transactional(readOnly = true)
class UserController {

def userCache
def springSecurityService
def utilityService

static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]


def create() {
List<Role> roles = Role.list()
Map roleMap = [:]
roles.each { role -> roleMap[role] = false }
render view: 'create', model: [userCO: new SaveUserCO(), roleMap: roleMap]
}

......
......
}

TestClass
import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import org.springframework.beans.factory.annotation.Autowired
import spock.lang.Specification

@Integration
@Rollback
class UserControllerSpec extends Specification {
@Autowired
UserController controller
}

def cleanup() {
}

void "test create render correct view and model when no role exists"() {
when:
controller.request.method='POST'
controller.create()

then:
assert controller.modelAndView.viewName == '/user/create'
assert controller.modelAndView.model.size() == 2
assert controller.modelAndView.model.roleMap.size() == 0
assert controller.modelAndView.model.userCO != null
}

void "test create render correct view and model when role exists"() {
when:
controller.request.method='POST'
createRole('ROLE_TEST')
controller.create()

then:
assert controller.modelAndView.viewName == '/user/create'
assert controller.modelAndView.model.size() == 2
assert controller.modelAndView.model.roleMap.size() == 1
assert controller.modelAndView.model.userCO != null
}
...
....
}

我将Grails 3.3.9与JDK 1.8,gormVersion 6.1.11和
gradle3.5

最佳答案

我的情况下,我有一个名为acceptance-test的文件夹,在该文件夹中有要执行的集成测试。我创建了一个类似于integration-test.gradleacceptanceTest gradle任务。

如果执行了acceptanceTest任务,则抛出BeanCreationException。我必须手动激活spring配置文件dev

./gradlew acceptanceTest -Dspring.profiles.active=test

根本问题是一些grails全局变量(例如 grailsApplicationmessageSource)未创建,需要运行测试。要运行集成测试,这些全局变量必须由Grails创建或模拟。将 spring.profile.active设置为 test会创建所有这些全局变量。

关于grails3 - 遇到错误,Spring BeanCreationException:创建名称为'validateableConstraintsEvaluator'的bean时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55045394/

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