(SpringMVC is the installed project in Webapps), then I get the following tomcat error dump:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Cannot create command without commandClass being set - either set commandClass or (in a form controller) override formBackingObject
with "root cause" (yeah, right):
java.lang.IllegalStateException: Cannot create command without commandClass being set - either set commandClass or (in a form controller) override formBackingObject
Ok, so, in the CarListController, I try to set a CommandClass (there is no "form" in this "simple" starter Spring MVC app):
Once I set the command class, all I get is "Requested Resource is Unavailable" no matter what the URL!
The entire CarListController class is this:
The Internet example I was trying to duplicate is at: http://maestric.com/doc/java/spring/mvc
Again, any help or suggestions would greatly be appreciated!
The command class is the class of the backing model object for that Controller - the Controller maps request parameters (like from a form) to populate fields of the command.
In all the examples you've given so far, you're trying to set the Controller class itself as the command class - this isn't going to work. In your example, either the Map from the ModelAndView or the List<Car> you're mapping to "carList" in the ModelAndView would serve this function.
However, I really don't see the need for using a command class at all - you're not going to be populating any data from the request - you're just displaying information - so you don't need to use a CommandController class at all. You should probably just be using an AbstractController rather than an AbstractCommandController.
Edit : The tutorial you linked is just using the "Controller" interface - so I'm not sure where AbstractCommandController came from...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Jul 12, 2002
Wow, thanks for your reply!
Sorry about my typo, my MyEclipse project code uses the same code as the Internet example.
Since I'm using MyEclipse and Spring 2.5, it's baffling what the problem might be.
Is there a way I could send you the Eclipse project code (or the Tomcat WAR file) for you to deploy to Tomcat to see what's going on?
I'm not sure how else I'm going to get a "Hello World" Spring MVC application working without an expert taking a quick look. Spring MVC isn't the easiest thing to get working initially, apparently.
I understand if you're too busy for request like I'm making, but I thought I'd ask (BTW, I ordered "Spring Recipes", so that book may help, but I'm concerned that something so basic isn't working...).
Look forward to your reply.
Joined: Jul 10, 2009
Mike London wrote:
I understand if you're too busy for request like I'm making, but I thought I'd ask (BTW, I ordered "Spring Recipes", so that book may help, but I'm concerned that something so basic isn't working...)
If you are looking only for a basic spring app then the MVC-step-by-step tutorial that comes along with the spring dist should be a good place to start.
Feel free to email the code (you can get my email by clicking on my name to the left) - but if it's the same code as linked in the tutorial - I can just get it from there.
BTW - Are you sure it's really just a typo in the forum? In the code you posted CarListController is extending AbstractCommandController - which is the only reason you would get an error saying that you need to set a command class...
Does your CarListController extend AbstractCommandController or implement Controller like the tutorial you linked to?
Joined: Jul 12, 2002
You're the man!
Yes, I did actually have a typo. Didn't think so, of course, in my last reply, but it was there.
Once I change the class to "implement Controller", implemented the correct method, and modified the ViewResolver so it'd look in the WEB-INF/jsp directory, it worked!!!
I'll be glad to send you the Eclipse project in case others would like to see a working example so they don't have the frustration I did.
In any case, THANK YOU for your kind offer to look at the project.