I'm new to Spring MVC and trying to learn from some web tutorials and Spring's PetClinic. When I was just starting I was using some tutorials from some really old releases of Spring. I didn't know it at the time, so it has been a lot of back and an regroup attempts. I am having trouble with the way my test site finds the Controller classes. The site finds my index.jsp file and executes that just fine. But when I try to click on a link that maps to one the the Controller classes I get a page not found (404) error.
Everything compiles and deployes with no errors on JBoss EAP 6.1. I'm attaching some of the snippets from my config files. Can somebody look at them and see what I'm doing wrong>
Web.xml snippet:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:resources/spring/core-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
the dispatcher servlet.xml snippet:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<bean class="org.S2Me.MyHealth.controller.CustomMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.springframework.web.servlet.PageNotFound">notFound</prop>
<prop key="java.lang.Exception">failure</prop>
</props>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
>
<property name="basename" value="/WEB-INF/messages" />
</bean>
the core-Servlet snippet:
<import resource="view-config.xml"/>
<context:component-scan base-package="org.S2Me.MyHealth.controller" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<mvc:view-controller path="/" view-name="index" />
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
p:basename="messages/messages" />
<bean
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"
>
<property name="defaultErrorView" value="exception" />
<!-- results into 'WEB-INF/jsp/exception.jsp' -->
<property name="warnLogCategory" value="warn" />
</bean>
the view-Servlet snippet:
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
>
<property name="contentNegotiationManager" ref="cnManager" />
<property name="viewResolvers">
<list>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
>
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean
class="org.springframework.web.servlet.view.BeanNameViewResolver" />
</list>
</property>
</bean>
<bean id="cnManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="true"/>
<property name="ignoreAcceptHeader" value="true"/>
<property name="defaultContentType" value="text/html"/>
<property name="mediaTypes">
<map>
<entry key="html" value="text/html" />
<entry key="xml" value="application/xml" />
<entry key="atom" value="application/atom+xml" />
</map>
</property>
</bean>
The index.jsp snippet:
<div class="navbar-inner">
<ul class="nav">
<li style="width: 100px;"><a href="<spring:url value="/" htmlEscape="true" />"><i class="icon-home"></i>
Home</a></li>
<li style="width: 130px;">
<a href="<spring:url value="/login" htmlEscape="true" />"> Login</a>
</li>
</ul>
</div>
The Login Controller class:
package org.S2Me.MyHealth.controller;
import org.S2Me.MyHealth.server.LoginForm;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.validation.BindingResult;
import java.util.Map;
import javax.validation.Valid;
@Controller
@RequestMapping("/login")
public class LoginController
{
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(method = RequestMethod.GET)
public String showForm(Map model)
{
LoginForm loginForm = new LoginForm();
model.put("loginForm", loginForm);
return "loginform";
}
@RequestMapping(method = RequestMethod.POST)
public String processForm(@Valid LoginForm loginForm, BindingResult result,
Map model)
{
String userName = "UserName";
String password = "password";
if (result.hasErrors())
{
return "loginform";
}
loginForm = ( LoginForm) model.get("loginForm");
if (!loginForm.getUserName().equals(userName)
|| !loginForm.getPassword().equals(password))
{
return "loginform";
}
model.put("loginForm", loginForm);
return "loginsuccess";
}
}
Any syntax errors are my cutting and pasting like I said no error in compile or deployment, just 404 errors on navigation. Any help would be appreciated. Thanks
DispatcherServletservlet load the 'core-servlet.xml' instead.