Spring boot: error asking to implement all methods

2019-07-26 06:43发布

Why is this happening? It didn't happen when I worked on a spring project in STS few months back. I have imported the following in the class:

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

enter image description here

Following is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.abcd</groupId>
    <artifactId>abcd</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>abcd</name>
    <description></description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

1条回答
手持菜刀,她持情操
2楼-- · 2019-07-26 07:16

A Custom Repository has to be an interface and this has to extend from JpaRepository or CrudRepository or PagingAndSortingRepository or MongoRepository, so update by following way:

@Repository 
public interface UserRepository extends JpaRepository<User, Long> {....} 

REFERENCES

Official documentation on repositories core concepts

查看更多
登录 后发表回答