Peter Boomsma
Peter Boomsma

Reputation: 9806

How to install the Springframework CrudRepository?

I'm following this tutorial to create a CRUD application with Spring. I want to create a repository and I want it to extend the Spring CrudRepository:

package com.movieseat.repositories;

import java.io.Serializable;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;


import com.movieseat.models.Movie;

public interface MovieRepository extends CrudRepository<Movie, Serializable> {}

Visual Studio Code is saying:

The import org.springframework.data cannot be resolved

I've removed the repository folder in the .m2 folder and do a reinstall but still no success.

I think I'm missing a dependency in my pom.xml file but I can't found it which one.

//edit. Sharing the pom.xml that's in the back-end folder:

    <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>

        <artifactId>backend</artifactId>

        <name>backend</name>
        <description>The backend project</description>

        <parent>
            <groupId>com.jdriven.ng2boot</groupId>
            <artifactId>parent</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>

        <properties>
            <!-- The main class to start by executing java -jar -->
            <start-class>com.movieseat.Application</start-class>
        </properties>

        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>com.jdriven.ng2boot</groupId>
                <artifactId>frontend</artifactId>
                <version>${project.version}</version>
                <scope>runtime</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
            </dependency>
        </dependencies>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>

Upvotes: 3

Views: 13690

Answers (2)

AchillesVan
AchillesVan

Reputation: 4356

The gradle file in your tutorial imports the following Spring data JPA dependency

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    ...
}

It's maven equivalent is :

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>1.11.7.RELEASE</version>
</dependency>

So, you must add the above dependeny in your pom file.

Upvotes: 7

Varun Sood
Varun Sood

Reputation: 221

Use following Maven Dependency

<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons-core -->
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons-core</artifactId>
    <version>1.0.0.RELEASE</version>
</dependency>

You can change verison of it depending upon Spring version you are using. User following link. https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons-core

Upvotes: 2

Related Questions