Hello,
I have a bean which i want to validate using my Validator implementation.
This Validator implementation i have declared as inner class.
But a context initialization failed exception is occuring with the details as follows:
Code:Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ng bean with name 'customerFormValidator' defined in ServletContext resource [/W EB-INF/app-servlet.xml]: Instantiation of bean failed; nested exception is org .springframework.beans.BeanInstantiationException: Could not instantiate bean cl ass [com.models.CustomerBean$CustomerBeanValidator]: No default constructo r found; nested exception is java.lang.NoSuchMethodException: com.models.C ustomerBean$CustomerBeanValidator.<init>() Caused by: org.springframework.beans.BeanInstantiationException: Could not insta ntiate bean class [com.models.CustomerBean$CustomerBeanValidator]: No defa ult constructor found; nested exception is java.lang.NoSuchMethodException: com. models.CustomerBean$CustomerBeanValidator.<init>() Caused by: java.lang.NoSuchMethodException: com.models.CustomerBean$Custom erBeanValidator.<init>() at java.lang.Class.getConstructor0(Class.java:2647) at java.lang.Class.getDeclaredConstructor(Class.java:1953) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:6 0) at org.springframework.beans.factory.support.SimpleInstantiationStrategy .instantiate(SimpleInstantiationStrategy.java:45) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.instantiateBean(AbstractAutowireCapableBeanFactory.java:701) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:687) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBean(AbstractAutowireCapableBeanFactory.java:388) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb ject(AbstractBeanFactory.java:250) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr y.getSingleton(DefaultSingletonBeanRegistry.java:141) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:247) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:161) at org.springframework.beans.factory.support.BeanDefinitionValueResolver .resolveReference(BeanDefinitionValueResolver.java:245) at org.springframework.beans.factory.support.BeanDefinitionValueResolver .resolveValueIfNecessary(BeanDefinitionValueResolver.java:124) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1019) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.populateBean(AbstractAutowireCapableBeanFactory.java:809) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBean(AbstractAutowireCapableBeanFactory.java:425) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb ject(AbstractBeanFactory.java:250) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr y.getSingleton(DefaultSingletonBeanRegistry.java:141) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:247) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:161) at org.springframework.beans.factory.support.DefaultListableBeanFactory. preInstantiateSingletons(DefaultListableBeanFactory.java:273) at org.springframework.context.support.AbstractApplicationContext.refres h(AbstractApplicationContext.java:346) at org.springframework.web.context.support.AbstractRefreshableWebApplica tionContext.refresh(AbstractRefreshableWebApplicationContext.java:156) at org.springframework.web.servlet.FrameworkServlet.createWebApplication Context(FrameworkServlet.java:308) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationCo ntext(FrameworkServlet.java:252) at org.springframework.web.servlet.FrameworkServlet.initServletBean(Fram eworkServlet.java:221) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean. java:115) at javax.servlet.GenericServlet.init(GenericServlet.java:212)
The code snippet from my app-servlet.xml is as follows :
Code:<bean id="customerFormController" class="com.controllers.CustomerFormController"> <property name="formView"> <value>client.htm</value> </property> <property name="successView"> <value>client.htm</value> </property> <property name="commandName" value="customerBean" /> <property name="commandClass"> <ref bean="customerBean" /> </property> <property name="validator"> <ref bean="customerFormValidator" /> </property> <property name="validateOnBinding"> <value>true</value> </property> <property name="pageCaption"> <value>Clients</value> </property> </bean> <bean id="customerBean" class="com.models.CustomerBean" /> <bean id="customerFormValidator" class="com.models.CustomerBean$CustomerBeanValidator" />
My bean code snippet is as follows:
Code:public class CustomerBean { private String customerName; private String companyName; public void setCustomerName(String customerName) { this.customerName = customerName; } public String getCustomerName() { return customerName; } public void setCompanyName(String companyName) { this.companyName = companyName; } public String getCompanyName() { return companyName; } /** * Validates the customer's details submitted. * */ protected class CustomerBeanValidator implements Validator { public CustomerBeanValidator() { } /** * Returns true if this validator can validate instances of supplied clazz, * else false. * *@param clazz : the class that this Validator is being asked to validate */ public boolean supports(Class clazz) { return CustomerBean.class.isAssignableFrom(clazz); } /** * Validates the supplied "target" object, which must be of a Class for which the * supports(Class) method typically has(or would) return true. * The supplied "errors" instance can be used to report ant resulting validation errors. * * @param target : the object that is to be validated(can be "null") * @param errors : contextual state about the validation process(never "null") */ public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors,"customerName","required","Field is required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors,"companyName","required","Field is required"); } } }
Can anybody please let me know where i have gone wrong??
Thanks.


Reply With Quote
Z