我正在尝试使用SpringBoot创建一个新项目,@Controller批注似乎可以正常工作,但是Eclipse抱怨说它不是批注。有什么想法可以解决吗?
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gpID</groupId>
<artifactId>myApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>My App</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-youtube</artifactId>
<version>v3-rev177-1.22.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Controller.java
package myApp.controllers;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller // This line is not understood in Eclipse
@EnableAutoConfiguration
public class Controller {
@RequestMapping("/")
public String index() {
return "index";
}
}
您的代码令人困惑,但请准确地说:
import org.springframework.stereotype.Controller;
第一点应该解决您的“编译”问题;如果您不想混淆自己和代码的其他未来读者,则第2点非常重要。是的,java允许使用xY和zY类名;但如果可能的话:请避免!您会看到,当在一个类中以两种不同的含义使用名称Y时,例如,必须始终使用xY和zY之类的绝对名称。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句