Không import được gói spring framework mặc dù đã khai báo dependency trong pom.xml khi lập trình spring mvc

Mình đã khai báo thư viện tại pom nhưng khi tạo package mới và bắt đầu code thì code của mình báo lỗi the “import org.springframework cannot be resolved eclipse”. Khi dùng spring boot thì mọi thứ lại bình thường ạ. Rất mong ai đó đã bị qua trường hợp này vào giúp mình ạ. mình cảm ơn

Đây là error log và folder chứa thư viện của mình

merged and moved by noname00

Hi Dung,
Cậu có thể share cho bọn tớ nội dung file pom.xml của cậu được không?

3 Likes
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">


  <modelVersion>4.0.0</modelVersion>
  <groupId>Shopping.WebApp</groupId>
  <artifactId>SpringMVC.WebApp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>SpringMVC.WebApp</name>


<properties>
    <java-version>1.7</java-version>
</properties>

<repositories>
    <!-- Repository for ORACLE JDBC Driver -->
    <repository>
        <id>codelds</id>
        <url>https://code.lds.org/nexus/content/groups/main-repo</url>
    </repository>
</repositories>

<dependencies>

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

    <!-- Servlet API -->
    <!-- http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- Jstl for jsp page -->
    <!-- http://mvnrepository.com/artifact/javax.servlet/jstl -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>


    <!-- JSP API -->
    <!-- http://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
    </dependency>
     
   <!-- Apache Commons FileUpload -->
   <!-- http://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
   <dependency>
       <groupId>commons-fileupload</groupId>
       <artifactId>commons-fileupload</artifactId>
       <version>1.3.1</version>
   </dependency>        

    <!-- Spring dependencies -->
    <!-- http://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.2.5.RELEASE</version>
    </dependency>

    <!-- http://mvnrepository.com/artifact/org.springframework/spring-web -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.2.5.RELEASE</version>
    </dependency>
    <dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context</artifactId>
		<version>4.3.17.RELEASE</version>
	</dependency>


    <!-- http://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.2.5.RELEASE</version>
    </dependency>

    <!-- http://mvnrepository.com/artifact/org.springframework/spring-orm -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.2.5.RELEASE</version>
    </dependency>

    <!-- Spring Security Artifacts - START -->
    <!-- http://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.0.4.RELEASE</version>
    </dependency>

    <!-- http://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>4.0.4.RELEASE</version>
    </dependency>

    <!-- http://mvnrepository.com/artifact/org.springframework.security/spring-security-taglibs -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>4.0.4.RELEASE</version>
    </dependency>
     
    <!-- Spring Security Artifacts - END -->

    <!-- Hibernate -->
    <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.10.Final</version>
    </dependency>

    <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.2.10.Final</version>
    </dependency>


    <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>5.2.10.Final</version>
    </dependency>


    <!-- MySQL JDBC driver -->
    <!-- http://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.34</version>
    </dependency>

    <!-- Oracle JDBC driver -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
    </dependency>

    <!-- SQLServer JDBC driver (JTDS) -->
    <!-- http://mvnrepository.com/artifact/net.sourceforge.jtds/jtds -->
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.3.1</version>
    </dependency>
     
    <!-- SQLServer JDBC driver (MSSQL-JDBC) -->
    <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.1.0.jre7</version>
    </dependency>
     
    <!-- PostgreSQL driver -->
    <!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901-1.jdbc4</version>
    </dependency>

     

    <!-- Email validator,... -->
    <!-- http://mvnrepository.com/artifact/commons-validator/commons-validator -->
    <dependency>
        <groupId>commons-validator</groupId>
        <artifactId>commons-validator</artifactId>
        <version>1.5.0</version>
    </dependency>

</dependencies>


<build>
    <finalName>SpringMVCAnnotationShoppingCart</finalName>
    <plugins>

        <!-- Config: Maven Tomcat Plugin -->
        <!-- http://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat7-maven-plugin -->
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <!-- Config: contextPath and Port (Default - /SpringMVCAnnotationShoppingCart
                : 8080) -->
            <!-- <configuration> <path>/</path> <port>8899</port> </configuration> -->
        </plugin>
    </plugins>
</build>
Đây là tệp pom của mình ạ

Mình đã fix được lỗi rồi nha. lỗi này nằm trong file maven. clear toàn bộ folder: “.m2/reponsitory” Sau đó build lại là fix được ạ. Mình xin cảm ơn

2 Likes

chuẩn rồi đấy. :relaxed:

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?