Spring MVC annotations are not working on Maven

0
Hello, I'm having a problem setting up Spring MVC in Maven , when I try to access the link it returns on browser:

  

STATUS 404 The requested resource is not available.

And the WARNING:

  

No mapping found for HTTP request with URI [/ spring / olaWorldSpring] in   DispatcherServlet with name 'Spring MVC Dispatcher Servlet'.

The context is ok:

  

Sep 05, 2016 9:45:24 PM   org.springframework.beans.factory.xml.XmlBeanDefinitionReader   loadBeanDefinitions INFORMAÇÃO: Loading XML bean definitions from   ServletContext resource [/WEB-INF/spring-context.xml]

Controller :

package br.com.jayybe.spring;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class Controle {

  @RequestMapping("/olaMundoSpring")
  public String execute() {
      System.out.println("Executando a lógica com Spring MVC");
      return "ok";
  }
}

web.xml:

<web-app><display-name>ArchetypeCreatedWebApplication</display-name><servlet><servlet-name>SpringMVCDispatcherServlet</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><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>SpringMVCDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>

spring-context.xml:

<?xmlversion="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.jayybe.spring" />
  <mvc:annotation-driven />

  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
  </bean>

</beans>

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0     http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.jayybe</groupId>
  <artifactId>spring</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>spring Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
    </dependency>
    <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                    <version>4.2.4.RELEASE</version>
              </dependency>

              <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-webmvc</artifactId>
                    <version>4.2.4.RELEASE</version>
              </dependency>
              <!-- Servlet -->
              <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>javax.servlet-api</artifactId>
                    <version>3.1.0</version>
              </dependency>
              <dependency>
                    <groupId>javax.servlet.jsp</groupId>
                    <artifactId>jsp-api</artifactId>
                    <version>2.1</version>
                    <scope>provided</scope>
              </dependency>
              <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>jstl</artifactId>
                    <version>1.2</version>
              </dependency>
  </dependencies>
  <build>
    <finalName>spring</finalName>
  </build>
</project>
    
asked by anonymous 06.09.2016 / 17:41

1 answer

0

You need to create the Spring configuration class

@Configuration
@ComponentScan(basePackageClasses = { Controle.class })
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {

}

There you will need to import some methods and you will need to configure them.

    
21.09.2016 / 17:16