• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring MVC dirt-simple app won't work

 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must have a Spring MVC 2.5 configuration problem, but I can't seem to figure out what it is...

I'm getting a "resource unavailable" error no matter what I type in to the URL.

Both files below are in the WEB-INF Folder.

Here's the web.xml:



Here's the associated springmvc-servlet.xml file:



This Servlet is apparently not even loading. Well, it does come up in the Tomcat Manager, but if I click that link, I get another Resource Not Available error.

URLs like: http://localhost:8000/SpringMVC/springmvc/list_cars.html

do not work under Tomcat 6.0.18.

Note: "SpringMVC" is the name of the deployed project under Webapps.

(Confused.)

Any suggestions would be greatly appreciated!

Thanks.

Mike
 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As more information about my original posting above, if I try to use the following URL:

http://localhost:8000/SpringMVC/list_cars.html

(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
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

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
org.springframework.web.servlet.mvc.BaseCommandController.createCommand(BaseCommandController.java:358)
org.springframework.web.servlet.mvc.BaseCommandController.getCommand(BaseCommandController.java:344)
org.springframework.web.servlet.mvc.AbstractCommandController.handleRequestInternal(AbstractCommandController.java:81)
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

----------

Ok, so, in the CarListController, I try to set a CommandClass (there is no "form" in this "simple" starter Spring MVC app):

public CarListController()
{
setCommandClass(CarListController.class);
}

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!

Thanks.

Mike
 
Collin Dugas
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding in the

Have'nt worked on it and not sure if it will work. Just a suggestion.
 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding: <property name="commandClass" value="web.carListController"/>

resulted in a syntax error in the springmvc-servlet.xml.

Is this what you meant?

Mike
 
Collin Dugas
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure why. My bean is something like


Any the command class is not the controller but the model object.

Not an expert in this. If this does not work i don know what to do.
 
Amit kull
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. The command class should be a bean with getters and setters. Not a controller.

The command class would probably get a car object from the screen and it will be then used by the business logic.
 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking at the tutorial at:

http://maestric.com/doc/java/spring/mvc

I don't see any mention of a CommandClass.

This is really confusing. I must be missing something....

In the above-referenced tutorial, there are two beans: Car and Brand (where the Brand class is a member of the Car class). Neither seems like a good candidate for a command class.

Can anyone else get this tutorial working in Eclipse?

Mike
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nathan,

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.

Thanks!

-- Mike
 
Collin Dugas
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nathan,

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.

It's good to have a starting point now.

Thanks.

-- Mile
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic