簡體   English   中英

即使在 build.gradle 中指定,也無法解析符號“EnableJpaRespositories”

[英]Cannot resolve symbol 'EnableJpaRespositories' even though specified in build.gradle

出於某種原因,我無法在我的項目中獲取一個模塊來檢測它是否具有獲取@EnableJpaRepositories的依賴項。 盡管在我的 build.gradle 文件中指定了implementation 'org.springframework.boot:spring-boot-starter-data-jpa' ,但當我運行 gradle 嘗試編譯時,我收到以下錯誤:

./gradlew clean build 

> Task :rest:compileJava FAILED
/Users/pasdeignan/git/pasciifinance/rest/src/main/java/com/pasciitools/pasciifinance/rest/PasciifinanceApplication.java:22: error: cannot find symbol
@EnableJpaRespositories(basePackages="com.pasciitools.pasciifinance")
 ^
  symbol: class EnableJpaRespositories
1 error

FAILURE: Build failed with an exception.

背景

I have a multi-module Spring project that I'm building where I'm trying to store the JPA pieces in a common module and the REST services in a rest module. rest模塊也是我的SpringBootApplication所在的位置。 當我啟動應用程序時,我收到以下錯誤:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field accountRepo in com.pasciitools.pasciifinance.rest.PasciifinanceApplication required a bean of type 'com.pasciitools.pasciifinance.common.repositories.AccountRepository' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.pasciitools.pasciifinance.common.repositories.AccountRepository' in your configuration.

項目結構

pasciifinance
└── build.gradle (empty)
└── settings.gradle
└── common
     └── build.gradle
     └── src
          └── main/java/com/pasciitools/pasciifinance/common
                └── entity
                └── repository
                    └── AccountRepository.java
└── rest
     └── build.gradle
     └── src
         └── main/java/com/pasciitools/pasciifinance/rest
             └── PasciiFinanceApplication.java
             └── restservice
                 └── RestService.java

PasciiFinanceApplication.java

package com.pasciitools.pasciifinance.rest;

import com.pasciitools.pasciifinance.common.entity.Account;
import com.pasciitools.pasciifinance.common.entity.AccountEntry;
import com.pasciitools.pasciifinance.common.repository.AccountEntryRepository;
import com.pasciitools.pasciifinance.common.repository.AccountRepository;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.List;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;


@EnableEncryptableProperties
@EnableJpaRespositories(basePackages="com.pasciitools.pasciifinance")
@SpringBootApplication(scanBasePackages = "com.pasciitools.pasciifinance")
public class PasciifinanceApplication {


    @Autowired
    private AccountRepository accountRepo;

    @Autowired
    private AccountEntryRepository entryRepo;

    private static final Logger log = LoggerFactory.getLogger(PasciifinanceApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(PasciifinanceApplication.class, args);
    }
}

build.gradle(其余模塊)


plugins {
    id 'org.springframework.boot' version '2.4.3'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.pascii-tools'
version = '0.0.1-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation project(':common')
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    implementation 'org.apache.poi:poi:5.0.0'
    implementation 'org.apache.poi:poi-ooxml:5.0.0'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
    implementation 'com.github.ulisesbocchio:jasypt-spring-boot:3.0.3'
    implementation 'org.springframework.boot:spring-boot-starter-batch'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    runtimeOnly 'com.h2database:h2'
}

test {
    useJUnitPlatform()
}

build.gradle(常用)

plugins {
    id 'org.springframework.boot' version '2.4.3'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.pascii-tools'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11

repositories {
    mavenCentral()
}

bootJar {
    enabled = false
}

jar {
    enabled = true
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

您在@EnableJpaRespositories中有錯字。

正如您在問題中提出的那樣,您需要將其重命名為@EnableJpaRepositories

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM