Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error importing Spring Context Annotation

When I import a Controller annotation on Spring, the following error occours:

The import org.springframework.stereotype.Controller conflicts with a type defined in the same file

Here goes the (very simple) code of my starting web-MVC project:

package com.company.project.servlet;

import org.springframework.stereotype.Controller;

@Controller
public class Controller {

    public String execute(){
        System.out.println("Controller executing...");
        return("page");
    }
}

As you can see, it is aparently no reason to an error be shown here. Have you any idea on what should be happening? Thanks!

Usefull information: - Eclipse Spring Tool Suite 3.3.0 (over Kepler) - Eclipse jars version 4.0.0.M1 (It should be the lattest versions of all these stuff)

like image 222
Alex Avatar asked Jul 23 '13 14:07

Alex


2 Answers

@Controller is a keyword, so choose another class name.

like image 168
Amuthan S Avatar answered Nov 03 '22 22:11

Amuthan S


The message says it all :

The import org.springframework.stereotype.Controller conflicts with a type defined in the same file

You have defined a single type in your file: the class Controller, which conflicts with the annotation Controller.

@Controller ---> same name
                     ^
                     |
public class Controller {

Choose another name, or use the fully qualified name of the enum:

@org.springframework.stereotype.Controller 
public class Controller {
like image 32
JB Nizet Avatar answered Nov 03 '22 21:11

JB Nizet