Spring boot 找不到Spring Web流验证程序

Spring boot 找不到Spring Web流验证程序,spring-boot,spring-webflow,Spring Boot,Spring Webflow,我试图在SpringWebFlow中进行表单验证。为此,我使用了一个验证器类,它以模型命名。正如文档中所述。 验证器被实例化为bean,但在验证过程中从未被调用。在这个问题上有什么建议吗 流量配置 Mapping request with URI '/totp/create' to flow with id 'totp/create' Resuming flow execution with key 'e5s1 Locking conversation 5 Getting flow execut

我试图在SpringWebFlow中进行表单验证。为此,我使用了一个验证器类,它以模型命名。正如文档中所述。 验证器被实例化为bean,但在验证过程中从未被调用。在这个问题上有什么建议吗

流量配置

Mapping request with URI '/totp/create' to flow with id 'totp/create'
Resuming flow execution with key 'e5s1
Locking conversation 5
Getting flow execution with key 'e5s1'
Getting FlowDefinition with id 'totp/create'
Resuming in org.springframework.webflow.mvc.servlet.MvcExternalContext@2b551393
Restoring [FlowVariable@3b66a2de name = 'key', valueFactory = [BeanFactoryVariableValueFactory@2fbc89 type = TOTPKey]]
Processing user event 'submit'
Resolved model twofa.core.domain.TOTPKey@505439d0
Binding to model
Adding default mapping for parameter 'execution'
Adding default mapping for parameter 'totpKeyId'
Adding default mapping for parameter 'token'
Adding empty value mapping for parameter 'eventId_submit'
Validating model
Event 'submit' returned from view [ServletMvcView@19f8532f view = org.springframework.web.servlet.view.velocity.VelocityLayoutView: name '/templates/totp/create/create'; URL [/templates/totp/create/create.vm]]
Executing [Transition@2feb5361 on = submit, to = successfullyCreated]
Exiting state 'createTotpKeyView'
Entering state 'successfullyCreated' of flow 'totp/create'
Executing org.springframework.webflow.action.ViewFactoryActionAdapter@423fa131
Rendering MVC [org.springframework.web.servlet.view.velocity.VelocityLayoutView: name '/templates/totp/create/success'; URL [/templates/totp/create/success.vm]] with model map [{currentUser=null, flashScope=map[[empty]], flowRequestContext=[RequestControlContextImpl@70144045 externalContext = org.springframework.webflow.mvc.servlet.MvcExternalContext@2b551393, currentEvent = submit, requestScope = map[[empty]], attributes = map[[empty]], messageContext = [DefaultMessageContext@149807b4 sourceMessages = map[[null] -> list[[empty]]]], flowExecution = [FlowExecutionImpl@1c4b2c3e flow = 'totp/create', flowSessions = list[[FlowSessionImpl@6eea5d26 flow = 'totp/create', state = 'successfullyCreated', scope = map['key' -> twofa.core.domain.TOTPKey@73f32d0a]]]]], flowExecutionKey=e5s1, flowExecutionUrl=/totp/create?execution=e5s1, key=twofa.core.domain.TOTPKey@73f32d0a}]
Finished executing org.springframework.webflow.action.ViewFactoryActionAdapter@423fa131; result = success
Completed transition execution.  As a result, the flow execution has ended
Removing flow execution '[Ended execution of 'totp/create']' from repository
Ending conversation 5
Unlocking conversation 5

这是在视图状态下调用的操作

CreateTopKeyAction

@组件
公共类CreateTopKeyAction实现操作
{
字符串uid=“随机”;
@凌驾
公共事件执行(RequestContext上下文)引发异常
{
尝试
{
//创建TOTP键并将其放入视图范围
TOTPKey TOTPKey=client.createTotpKeyForUid(uid,null);
context.getViewScope().put(“key”,totpKey);
返回新事件(本“成功”);
}
捕获(例外e)
{
log.error(“为用户创建TOTP密钥时出错:“+uid+”\n“+e.getMessage());
//将响应消息放在闪存范围内,以显示一次
context.getFlashScope().put(“fetchingError”,true);
返回新事件(此“错误”);
}
}
}
这就是我正在尝试使用的验证器编辑重命名以匹配文档

密钥验证程序

@组件
公共类密钥验证器
{
[...]
public void validateCreateTopKeyView(TOTPKey,ValidationContext上下文)
{
System.out.println(“验证视图状态”);
}
公共void验证(TOTPKey,ValidationContext)
{
System.out.println(“默认验证”);
}
}
我还尝试了不同的命名方案,如
TOTPKeyValidator
TOTPKeyValidator
。他们都没有工作

唯一有效的方法是在
TOTPKey
类中创建一个验证方法,但我不想使用这种方法

此外,这是在尝试验证期间生成的日志文件

日志

Mapping request with URI '/totp/create' to flow with id 'totp/create'
Resuming flow execution with key 'e5s1
Locking conversation 5
Getting flow execution with key 'e5s1'
Getting FlowDefinition with id 'totp/create'
Resuming in org.springframework.webflow.mvc.servlet.MvcExternalContext@2b551393
Restoring [FlowVariable@3b66a2de name = 'key', valueFactory = [BeanFactoryVariableValueFactory@2fbc89 type = TOTPKey]]
Processing user event 'submit'
Resolved model twofa.core.domain.TOTPKey@505439d0
Binding to model
Adding default mapping for parameter 'execution'
Adding default mapping for parameter 'totpKeyId'
Adding default mapping for parameter 'token'
Adding empty value mapping for parameter 'eventId_submit'
Validating model
Event 'submit' returned from view [ServletMvcView@19f8532f view = org.springframework.web.servlet.view.velocity.VelocityLayoutView: name '/templates/totp/create/create'; URL [/templates/totp/create/create.vm]]
Executing [Transition@2feb5361 on = submit, to = successfullyCreated]
Exiting state 'createTotpKeyView'
Entering state 'successfullyCreated' of flow 'totp/create'
Executing org.springframework.webflow.action.ViewFactoryActionAdapter@423fa131
Rendering MVC [org.springframework.web.servlet.view.velocity.VelocityLayoutView: name '/templates/totp/create/success'; URL [/templates/totp/create/success.vm]] with model map [{currentUser=null, flashScope=map[[empty]], flowRequestContext=[RequestControlContextImpl@70144045 externalContext = org.springframework.webflow.mvc.servlet.MvcExternalContext@2b551393, currentEvent = submit, requestScope = map[[empty]], attributes = map[[empty]], messageContext = [DefaultMessageContext@149807b4 sourceMessages = map[[null] -> list[[empty]]]], flowExecution = [FlowExecutionImpl@1c4b2c3e flow = 'totp/create', flowSessions = list[[FlowSessionImpl@6eea5d26 flow = 'totp/create', state = 'successfullyCreated', scope = map['key' -> twofa.core.domain.TOTPKey@73f32d0a]]]]], flowExecutionKey=e5s1, flowExecutionUrl=/totp/create?execution=e5s1, key=twofa.core.domain.TOTPKey@73f32d0a}]
Finished executing org.springframework.webflow.action.ViewFactoryActionAdapter@423fa131; result = success
Completed transition execution.  As a result, the flow execution has ended
Removing flow execution '[Ended execution of 'totp/create']' from repository
Ending conversation 5
Unlocking conversation 5

它说
验证模型
,但什么也没发生…

这归结为我的验证器类中的一个错误的导入语句


使用
org.relaxng.datatype.ValidationContext
而不是
org.springframework.binding.validation.ValidationContext
将不起作用。

原因是我的验证器类中的导入语句错误


使用
org.relaxng.datatype.ValidationContext
而不是
org.springframework.binding.validation.ValidationContext
将不起作用。

我建议阅读。验证器的名称应与以下模式匹配
${model}验证器
。您的模型名为
key
。您的验证器应命名为
KeyValidator
。我试过了,它不起作用。请确保它确实被检测到(它必须在Spring Boot覆盖的包中,否则它不会被构造,也永远不会起作用)。它被检测为bean并被构造。我还在调试器中验证了这一点。在启动过程中调用构造函数,然后配置其他东西,bean就不可见了。但是你还没有发布这些信息。我建议你读一下。验证器的名称应与以下模式匹配
${model}验证器
。您的模型名为
key
。您的验证器应命名为
KeyValidator
。我试过了,它不起作用。请确保它确实被检测到(它必须在Spring Boot覆盖的包中,否则它不会被构造,也永远不会起作用)。它被检测为bean并被构造。我还在调试器中验证了这一点。在启动过程中调用构造函数,然后配置其他东西,bean就不可见了。但是你还没有发布这些信息。我以前做过类似的事情,没有注意到IDE自动完成中选择了错误的类:-)我以前做过类似的事情,没有注意到IDE自动完成中选择了错误的类:-)