Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import org.springframework cannot be resolve even after adding dependencies

I get errors that say The import org.springframework cannot be resolved for all the imports. My POM.XML is as follows: i am sure that i have included all the necessary dependencies. No clue, why this is happening. Help

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>com.app.controller</groupId>
    <artifactId>FirstController</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>webapp spring</name>
    <url>http://maven.apache.org</url>

    <properties>
        <spring.version>4.0.0.RELEASE</spring.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- Spring 3 dependencies -->


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


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>FirstController</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

FirstController.java

package my.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
@RequestMapping("/hi")
public class FirstController {
    @RequestMapping(method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Spring 3 MVC Hello LA");
        return "hello";
    }
}
like image 726
Sharon Watinsan Avatar asked Dec 25 '13 07:12

Sharon Watinsan


1 Answers

  • Check the output of mvn clean install. And see if the concerned jar is being downloaded. Look into $HOME/.m2/repo/.... to see if it is indeed present.

  • In the IDE be sure you have configured the Build Path correctly (e.g. in eclipse, Right-click project, Build-Path, 3rd tab)

  • Besides, I guess it should be pom.xml(lowercase) and not POM.XML, as I believe case matters. But I guess you put that in the post unkownigly.

like image 199
mtk Avatar answered Oct 01 '22 00:10

mtk