春天4休息问题

时间:2014-11-17 22:08:11

标签: spring-mvc

我正在尝试使用带有添加的restcontroller功能的spring 4创建一个spring mvc rest app但是我在restcontrollerclass中得到了一个错误,我无法解决。

我得到的错误就是这个

我无法导入org.springframework.web.bind.annotation.RestController;在我的restcontroller课程中,它下方标有红线。我有所有正确的罐子

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]

2 个答案:

答案 0 :(得分:0)

将其包含在您的Pom中:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${org.springframework.version}</version>
</dependency>

让我知道你是怎么走的。

答案 1 :(得分:0)

@RestController和你的类名(RestController)是冲突的。您不能在班级中使用相同的名称。更改类文件的名称。它应该工作。