Reputation: 827
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?
Upvotes: 2
Views: 15668
Reputation: 985
**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";
}
}
Upvotes: 0
Reputation: 1193
Check the POM and do a maven update. make sure you have imported
import org.springframework.web.bind.annotation.RequestMapping;
Upvotes: 1