I am trying a basic spring mvc demo and when I run it on tomcat it hits a 404 error saying the servlet does not exists. My code is as follows:
web.xml
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
spring-mvc-demo-servlet
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="com.luv2code.springdemo" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
Home Controller
@Controller
public class HomeController {
@RequestMapping("/")
public String ShowMyPage()
{
return "main-menu";
}
}
Can anyone help me with this?
Try matching your example with my below working solution
web.xml at path spring-tutorial-mvc\WebContent\WEB-INF
The app-ctx.xml as below ,path : spring-tutorial-mvc\WebContent\WEB-INF
mvc-config.xml at path spring-tutorial-mvc\WebContent\WEB-INF
UserController.java at path spring-tutorial-mvc\src\com\spring\tutorial\controller
Here the url will be e.g. http://localhost://user/getAllUsers port : port of your server context-root is context path of your web application