Reputation: 1063
I am trying to create a new project with SpringBoot, the @Controller annotation seems to work but Eclipse is complaining saying it is not an annotation. Any ideas to resolve that ?
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";
}
}
Upvotes: 1
Views: 5709
Reputation: 1
if you want the name of the file to be "controller", you have to put annotation fully qualified annotation. otherwise it will work when you add @controller
Upvotes: 0
Reputation: 140417
Your code is confusing, but lets be precise:
import org.springframework.stereotype.Controller;
Point 1 should fix your "compile" problem; and point 2 is really essential if you don't want to confuse yourself and other future readers of your code. Yes, java allows for having x.Y and z.Y class names; but if possible: avoid it! You see, when you are using the name Y in two different meanings within one class, then for example, you have to use absolute names like x.Y and z.Y all the time.
Upvotes: 4
Reputation: 10666
You need to use the fully qualified name for the annotation since your class is named Controller
@org.springframework.stereotype.Controller
public class Controller {...
Upvotes: 1
Reputation: 387
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
maybe this ?
Upvotes: -1