Reputation: 1
I am trying to create a spring mvc rest app using spring 4 with the added restcontroller feature but i get an error inside the restcontrollerclass which i cant solve.
The error i get is this
I cannot import org.springframework.web.bind.annotation.RestController; to my restcontroller class it's marked with a red line underneath. I have got all the correct jars
Restcontroller
import org.springframework.web.bind.annotation.RequestMapping;
this is the line that is marked with a red line underneath
import org.springframework.web.bind.annotation.RestController;
if i remove the annotaion @Restcontroller the error disapears
so how do i import org.springframework.web.bind.annotation.RequestMapping; without getting an error
[code]
@RestController
@RequestMapping(value="/testrest")
public class RestController {
@RequestMapping("/greeting")
public String greeting(){
return "hello";
}
}
[/code]
pom.xml
[code]
<modelVersion>4.0.0</modelVersion>
<groupId>se.molin</groupId>
<artifactId>blogga</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<org.springframework.version>4.0.2.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.3.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.29</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<!-- projectNameTemplate>[artifactId]-[version]</projectNameTemplate -->
<wtpmanifest>true</wtpmanifest>
<wtpversion>2.0</wtpversion>
<useProjectReferences>false</useProjectReferences>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
[/code]
Upvotes: 0
Views: 378
Reputation: 627
@RestController and your class name(RestController) are conflicting. You can't have the same name in as class. Change the name of your class file. it should work.
Upvotes: 0
Reputation: 8414
Include this in your Pom:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
And let me know how you go.
Upvotes: 1