0

I've got a really annoying issue... I've not defined a Controller handler mapper and therefore I'm using the DefaultAnnotationHandlerMapping class. My issue seems to have something to do with the Controller bean name mapping to the Controller class e.g.

Incoming request to dispatcher -> index.htm

With the following Controller class:

@Controller
public class IndexController { 
    @RequestMapping(value = "/index.htm", method = RequestMethod.GET)
    public String loginForm(ModelMap model) {
        return "index";
    }  
}

Should map index.htm to indexController bean and then to IndexController class. I can see from the logs that Spring has registered the bean with the container however I get the following error:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [xxx.controller.IndexController] 

I know for certain that the class exists (because the bean name is derived from it).

The strange thing is that if I name my controller the same as the bean name (e.g. indexController) everything is fine!! (Obviously I don't want my classes to have a lower case first letter!!)

Just to note that I've used the following in my dispatcher-servlet.xml:

<mvc:annotation-driven />
<context:component-scan base-package="xxx" />

JLove

2 Answers 2

2

This error usually means your class has not been bundled in the war file. Unzip the war file and check your class is included correctly.

I suspect you successfully bundled "indexController.class" at some point, but prior packaging attempts failed. You haven't indicated how you are packaging your application, check your Maven/Ant configuration if you are using one of those. Beware of sharing build directories between IDE and build script, as they can occasionally conflict with each other.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks... I believe that the issue was to do with the hot deployment used by Netbeans. Because I've only changed the case of the class name I think it did not believe the file had changed. I cleaned my project and re-deployed and all is fine!!
-1

I'd advice you to download STS and create new Spring MVC project template, to see, how Spring 3 MVC works.

1 Comment

I understand the principles used with Spring MVC... I'm asking for specific help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.