Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Spring Mvc 404 error



Hi:

I took a course on Spring 2.56 from Interface21 and the labs I got get it to work during the training.

But when I tried it at home it doesn't work.
I go to the following url and it's find.
http://localhost:8080/accounts/

It display "This is my JSP page. " This is from the default index.jsp page.
When I tried the url as suggested in the lab "http://localhost:8080/accounts/accountSummary.htm"

It gives me a 404 error.

Note, the Tomcat 6 console didnot show any errors meaning it didn't invoke the code for the url.
I am using Myeclipse 8 on Tomcat6.
Here is my Spring information:

Web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

contextConfigLocation
/WEB-INF/accounts-application-config.xml

org.springframework.web.context.ContextLoaderListener

accounts
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
/WEB-INF/accounts-servlet-config.xml

accounts
/accounts/*

Accounts-servlet-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

-->

accounts-application-config.xml:

?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

classpath:accounts/internal/Account.hbm.xml
classpath:accounts/internal/Beneficiary.hbm.xml

Here is the AccountControler.java:
package accounts.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import accounts.Account;
import accounts.AccountManager;

/**
* A Spring MVC @Controller controller handling requests for both the
* account summary and the account details pages. The accountDetails()
* method return an account, corresponding to a given entity id. The
* accountSummary() method returns a list with all accounts.
*/
@Controller
public class AccountController {

private AccountManager accountManager;

/**
* Creates a new AccountController with a given account manager.
*/
@Autowired public AccountController(AccountManager accountManager) {
this.accountManager = accountManager;
}

/**
* The @RequestMapping annotation takes care of setting the URL
* this controller will react this.
*/
@RequestMapping("/accountDetails.htm")
public ModelAndView accountDetails(HttpServletRequest request)
throws ServletRequestBindingException {
long id = ServletRequestUtils.getRequiredLongParameter(request, "entityId");
ModelAndView mav = new ModelAndView("accountDetails");
mav.addObject("account", accountManager.getAccount(id));
return mav;
}

@RequestMapping("/accountSummary.htm")
public ModelAndView accountSummary() {
List accounts = accountManager.getAllAccounts();
ModelAndView mav = new ModelAndView();
mav.setViewName("accountSummary");
mav.addObject("accounts", accounts);
return mav;
}
}

The database is hsqldb.

Any help or hint would be greatly appreciated it.

Yours,

Frustrated.