2

I'm just starting to study Spring Boot. I installed STS and created an application with Web + JPA + MySQL + DevTools + Security. When I'm creating my Controller and I note it with @RequestMapping, STS says RequestMapping can not be resolved to a type.

import org.springframework.stereotype.Controller;

@Controller
public class TestController {

    @RequestMapping("/test")    
    public String test() {
        return "test";
    }

}

EDIT

My pom.xml

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.heart</groupId>
<artifactId>echocardiogram</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>echocardiogram</name>
<description>Echocardiogram Management System</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

How do I solve this?

Luciano Borges
  • 817
  • 3
  • 12
  • 31
  • Possible duplicate of [What dependency is missing for org.springframework.web.bind.annotation.RequestMapping?](https://stackoverflow.com/questions/8422720/what-dependency-is-missing-for-org-springframework-web-bind-annotation-requestma) – Ori Marko Apr 12 '18 at 14:30
  • I don't think so. I put in my pom.xml the dependency to spring-boot-starter-web. – Luciano Borges Apr 12 '18 at 14:44
  • try this: [https://stackoverflow.com/a/8422799/3493036](https://stackoverflow.com/a/8422799/3493036) or just restart STS. – Patrick Apr 12 '18 at 14:45

2 Answers2

1

Check the POM and do a maven update. make sure you have imported

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

DEBENDRA DHINDA
  • 1,163
  • 5
  • 14
0

**You should add RequestMethodType as like GET/ POST/ PUT/ DELETE.**Here we use get method for return something

@Controller
public class TestController {
    @RequestMapping(value="/test",method=RequestMethod.GET)    
    public String test() {
        return "test";
    }
}
MangduYogii
  • 935
  • 10
  • 24