Olá, amigos. Fiz o curso de Spring MVC e fiz todos os exercícios, fui então criar um novo projeto para aplicar o Spring, mas infelizmente não consigo configurar na IDE. O curso já nos apresenta um projeto com a base utilizando o Spring e não como aderir o Spring à um projeto que criamos do zero.
Alguém pode me ajudar?
Obs: A aplicação está subindo no tomcat e abrindo a página index. Ao tentar acessar localhost:8080/NomeDoProjeto/teste, o controller não está sendo ativado.
Spring Context
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="br.com.leandro.projeto" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="conversionService"
class="org.springframework.context.support.ConversionServiceFactoryBean">
</bean>
<mvc:default-servlet-handler />
</beans>
WEB XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>contas</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- Declaracao do servlet do Spring MVC abaixo-->
<servlet>
<servlet-name>spring mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
JSP teste
<!DOCTYPE html>
<html>
<head>
</head>
<body>
JSP de Teste!
</body>
</html>
Controller de teste
package br.com.leandro.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class ProdutoController {
@RequestMapping("/teste")
public String teste() {
return "teste";
}
}