I am using mvc application with spring annotation support (version 3.2.5), basically I need to catch any wrong url for one method and then display an error message. For example, if my correct one url www.url.valid/loginmaps to the controller, if the user mistakenly inserts loginw or any invalid URL, it should map to the default controller.
I tried as follows:
package com.controller;
import static com.mns.utils.Constants.REGISTER_FAIL;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class DefaultSpringController {
@RequestMapping
public String forwardRequest(final HttpServletRequest request) {
return "redirect:/" + REGISTER_FAIL;
}
}
My application context is as follows:
<bean id="defaultSpringController" class="com.controller.DefaultSpringController">
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="defaultHandler" ref="defaultSpringController"/>
</bean
But the following error persisted:
nested exception is java.lang.ClassNotFoundException: com.controller.DefaultSpringController
I am not sure what I am missing here and the controller is in the correct package.
Any idea how I can achieve this, please?
Thanks in advance