我认为这个问题很常见,但由于某种原因我无法解决这个问题。
这是我得到的错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reverseController' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Validator [FormValidator@6b3ded0d] does not support command class [ReverseString]
这是我的 FormValidator 类中的支持方法:
public boolean supports(Class clazz) {
return ReverseController.class.isAssignableFrom(clazz);
}
这是我的 app-servlet.xml 上的 bean 定义:
<bean id="reverseController" class="ReverseController">
<property name="commandName"><value>reverseString</value></property>
<property name="commandClass"><value>ReverseString</value></property>
<property name="formView"><value>reverse</value></property>
<property name="successView"><value>reverseResult</value></property>
<property name="validator"><bean class="FormValidator" /></property>
最后,这是我的 ReverseController 的主要部分:
@Service
public class ReverseController extends SimpleFormController {
public ReverseController() {
//setCommandClass(ReverseString.class);
//setCommandName("reverseString");
}
private ReverseString reverseStringMaster;
@Autowired
public void setWriter(ReverseString reverseStringMaster) {
this.reverseStringMaster = reverseStringMaster;
}
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors) {
ReverseString revString = (ReverseString) command;
return new ModelAndView(getSuccessView(),"reversedString", revString);
}
public void init() {
System.out.println("Done");
}
}
知道可能导致该问题的原因是什么吗?