인프런 커뮤니티 질문&답변

jumong님의 프로필 이미지
jumong

작성한 질문수

실전! 스프링 데이터 JPA

순수 JPA 페이징과 정렬

jpaRepository 의존성 주입 중복문제????

작성

·

9.1K

0

안녕하세요 김영환 강사님
강의를 들으면서 다른 작업시 이러한 문제가 발생해서 진행이 안됩니다. 

org.springframework.beans.factory.UnsatisfiedDependencyException: 

Error creating bean with name 'adminBoardController' defined in file 

[C:\Users\web\projects\xxx-api\build\classes\java\main\com\xxx\xxxapi\controller\admin\AdminBoardController.class]: 

Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 

Error creating bean with name 'articleService' defined in file 

[C:\Users\web\projects\xxx-api\build\classes\java\main\com\xxx\xxxapi\service\ArticleService.class]: 

Unsatisfied dependency expressed through constructor parameter 0; 

nested exception is org.springframework.beans.factory.BeanCreationException: 

Error creating bean with name 'articleRepository' defined in com.xxx.xxxapi.repository.board.ArticleRepository 

defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: 

Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: 

Could not create query for public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Reason: Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]; 

nested exception is java.lang.IllegalArgumentException: 

Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]

 

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 

Error creating bean with name 'articleService' defined in file 

[C:\Users\web\projects\xxx-api\build\classes\java\main\com\xxx\xxxapi\service\ArticleService.class]: 

Unsatisfied dependency expressed through constructor parameter 0; 

nested exception is org.springframework.beans.factory.BeanCreationException: 

Error creating bean with name 'articleRepository' defined in com.xxx.xxxapi.repository.board.ArticleRepository 

defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: 

Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: 

Could not create query for public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Reason: Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]; 

nested exception is java.lang.IllegalArgumentException: 

Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]

 

Caused by: org.springframework.beans.factory.BeanCreationException: 

Error creating bean with name 'articleRepository' defined in com.xxx.xxxapi.repository.board.ArticleRepository 

defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: 

Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: 

Could not create query for public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Reason: Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]; 

nested exception is java.lang.IllegalArgumentException: 

Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]

 

Caused by: org.springframework.data.repository.query.QueryCreationException

Could not create query for public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Reason: Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]; 

nested exception is java.lang.IllegalArgumentException: 

Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]

 

Caused by: java.lang.IllegalArgumentException:

Failed to create query for method public abstract com.xxx.xxxapi.model.board.Article com.xxx.xxxapi.repository.board.ArticleRepository.findByHeadIdxAndAIdxNot(int,int)! 

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]

 

Caused by: java.lang.IllegalArgumentException:

Unable to locate Attribute  with the the given name [AIdx] on this ManagedType [com.xxx.xxxapi.model.board.Article]

어떤 문제인지 부탁드립니다 

답변 7

0

jumong님의 프로필 이미지
jumong
질문자

안녕하세요 제가 최대한 해 볼려고 했고 ㅜㅜ 말씀주신 문제되는 부분만을 추출하는 것도 어려워서

이렇게 문의 드립니다.

과거의 build.gradle로 문제가 없이 작동됩니다.

예전의 build.gradle 입니다 *************************************************

buildscript {

    repositories {

        mavenCentral()

        maven {

            url "https://plugins.gradle.org/m2/"

        }

    }

    ext {

        hibernateVersion = '5.1.0.Final'

        queryDSLVersion = '4.1.4'

    }

    dependencies {

        classpath("org.springframework.boot:spring-boot-gradle-plugin")

        classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.7"

        classpath "io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE"

    }

}

 

plugins {

    id 'org.springframework.boot' version '2.1.7.RELEASE'

    id 'java'

    id 'net.ltgt.apt' version '0.20'

}

 

apply plugin: 'io.spring.dependency-management'

apply plugin: 'war'

apply plugin: "com.ewerk.gradle.plugins.querydsl"

apply plugin: 'net.ltgt.apt-idea'

apply plugin: "io.spring.dependency-management"

 

sourceCompatibility = '1.8'

targetCompatibility = '1.8'

 

configurations {

    compileOnly {

        extendsFrom annotationProcessor

    }

    querydsl.extendsFrom compileClasspath

}

 

repositories {

    mavenCentral()

    maven { url 'https://repo.spring.io/libs-snapshot' }

}

 

bootRun {

    systemProperties System.properties

}

 

ext {

    mapstructVersion = "1.3.1.Final"

}

 

compileQuerydsl{

    options.annotationProcessorPath = configurations.querydsl

}

 

// querydsl 적용

def querydslSrcDir = project.buildDir.toString() + '/generated/sources/annotationProcessor/java/main'

 

querydsl {

    jpa = true

    querydslSourcesDir = querydslSrcDir

}

 

sourceSets {

    main {

        java {

            srcDirs = ['src/main/java', querydslSrcDir]

        }

    }

}

 

dependencies {

 

    //jsp, jstl

    compile group: 'javax.servlet', name: 'jstl', version: '1.2'

    compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '8.5.20'

    // https://mvnrepository.com/artifact/org.sitemesh/sitemesh

    compile group: 'org.sitemesh', name: 'sitemesh', version: '3.0.1'

    // https://mvnrepository.com/artifact/opensymphony/sitemesh

    compile group: 'opensymphony', name: 'sitemesh', version: '2.4.2'

    //qlrm

    compile group: 'ch.simas.qlrm', name: 'qlrm', version: '1.7.1'

    //database

    runtime("mysql:mysql-connector-java:5.1.41")

    compile("org.hibernate:hibernate-core:$hibernateVersion")

    compile("org.hibernate:hibernate-entitymanager:$hibernateVersion")

    compile("org.hibernate:hibernate-java8:$hibernateVersion")

    compile("com.querydsl:querydsl-jpa:${queryDSLVersion}")

    compile("com.querydsl:querydsl-apt:${queryDSLVersion}")

    compile("com.querydsl:querydsl-sql:${queryDSLVersion}")

    compile("com.querydsl:querydsl-sql-spring:${queryDSLVersion}")

    compile("com.vladmihalcea:hibernate-types-52:2.3.5")

 

    // Mybatis

    compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2")

 

    //commons

    compile("commons-io:commons-io:2.4")

    compile("commons-codec:commons-codec:1.10")

    compile("commons-fileupload:commons-fileupload:1.3.1")

    compile("commons-httpclient:commons-httpclient:3.1")

    compile("commons-logging:commons-logging:1.2")

    compile("commons-collections:commons-collections:3.2.2")

    compile("org.apache.commons:commons-csv:1.4")

    compile("org.apache.commons:commons-lang3:3.4")

 

    //jpa

    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.1.7.RELEASE'

 

    // etc

    compile("com.googlecode.json-simple:json-simple:1.1.1")

    compile("org.mindrot:jbcrypt:0.4")

    compile group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.46'

    compile 'org.springframework.boot:spring-boot-starter-web'

    compile("org.springframework.session:spring-session-core")

    compile("org.springframework.boot:spring-boot-starter-security")

    compile("com.squareup.okhttp3:okhttp:3.7.0")

    compileOnly 'org.projectlombok:lombok'

    runtimeOnly 'org.springframework.boot:spring-boot-devtools'

    annotationProcessor 'org.projectlombok:lombok'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'

 

    // local

    compile files('src/main/webapp/WEB-INF/lib/xalan.jar')

    compile files('src/main/webapp/WEB-INF/lib/commons-httpclient-3.0.jar')

    compile files('src/main/webapp/WEB-INF/lib/ExecureCrypto_v1.0_jdk14.jar')

   

    // mapstruct

    implementation "org.mapstruct:mapstruct:${mapstructVersion}"

    annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}

 

}

 

 

그리고 바꾼 즉 현재 문제가 발생되고 있는 build.gradle 입니다. ***********************************

 

plugins {
id 'java'
id 'war'
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
id 'net.ltgt.apt' version '0.20'
}

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
querydsl.extendsFrom compileClasspath
}

repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo.spring.io/libs-snapshot' }
}

test {
useJUnitPlatform()
}

compileQuerydsl{
options.annotationProcessorPath = configurations.querydsl
}

// querydsl 적용
def querydslSrcDir = project.buildDir.toString() + '/generated/sources/annotationProcessor/java/main'

querydsl {
jpa = true
querydslSourcesDir = querydslSrcDir
}

sourceSets {
main {
java {
srcDirs = ['src/main/java', querydslSrcDir]
}
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:2.5.4'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.4'
implementation 'org.springframework.boot:spring-boot-starter-jdbc:2.5.4'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.5.4'
implementation 'org.springframework.boot:spring-boot-starter-security:2.5.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.4'
implementation 'org.springframework.session:spring-session-core:2.5.3'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
runtimeOnly 'org.springframework.boot:spring-boot-devtools:2.5.4'
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'

//jsp, jstl
implementation 'javax.servlet:jstl:1.2'
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:10.0.8'

// https://mvnrepository.com/artifact/org.sitemesh/sitemesh
implementation 'org.sitemesh:sitemesh:3.0.1'
// https://mvnrepository.com/artifact/opensymphony/sitemesh
implementation 'opensymphony:sitemesh:2.4.2'
//qlrm
implementation 'ch.simas.qlrm:qlrm:1.7.1'

//database
runtime 'mysql:mysql-connector-java:8.0.25'
implementation 'org.hibernate:hibernate-core:5.6.1.Final'
implementation 'org.hibernate:hibernate-entitymanager:5.6.1.Final'
implementation 'org.hibernate:hibernate-java8:5.6.1.Final'
implementation 'com.vladmihalcea:hibernate-types-52:2.12.1'
implementation 'com.querydsl:querydsl-jpa:5.0.0'
implementation 'com.querydsl:querydsl-apt:5.0.0'
implementation 'com.querydsl:querydsl-sql:5.0.0'
implementation 'com.querydsl:querydsl-sql-spring:5.0.0'

// Mybatis
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0'

//commons
implementation 'commons-io:commons-io:20030203.000550'
implementation 'commons-codec:commons-codec:20041127.091804'
implementation 'commons-fileupload:commons-fileupload:1.4'
implementation 'commons-httpclient:commons-httpclient:20020423'
implementation 'commons-logging:commons-logging:1.2'
implementation 'commons-collections:commons-collections:20040616'
implementation 'org.apache.commons:commons-csv:1.8'
implementation 'org.apache.commons:commons-lang3:3.12.0'

// etc
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation 'org.mindrot:jbcrypt:0.4'
implementation 'org.bouncycastle:bcprov-jdk16:1.46' //cf signed url 만들 때

// local
implementation files('src/main/webapp/WEB-INF/lib/xalan.jar')
implementation files('src/main/webapp/WEB-INF/lib/commons-httpclient-3.0.jar')
implementation files('src/main/webapp/WEB-INF/lib/ExecureCrypto_v1.0_jdk14.jar')

// mapstruct
implementation "org.mapstruct:mapstruct:1.4.2.Final"
annotationProcessor "org.mapstruct:mapstruct-processor:1.4.2.Final"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:1.4.2.Final"
}

bootRun {
String activeProfile = System.properties['spring.profiles.active']
systemProperty "spring.profiles.active", activeProfile
}

부탁드립니다 감사합니다.

김영한님의 프로필 이미지
김영한
지식공유자

jumong님 죄송하지만 이렇게 주시면 도움을 드리기 어렵습니다.

동작하는 완전한 프로젝트를 2벌 만들어주세요.

감사합니다.

0

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. jumong님

문제가 되는 부분만 따로 프로젝트로 만들고 프로젝트를 압축해서 구글 드라이브로 공유해서 링크를 남겨주세요.

구글 드라이브 업로드 방법은 다음을 참고해주세요.

https://bit.ly/3fX6ygx

 

주의: 업로드시 링크에 있는 권한 문제 꼭 확인해주세요

 

추가로 다음 내용도 코멘트 부탁드립니다.

1. 실행 방법을 알려주세요.

2. 어떻게 문제를 확인할 수 있는지 자세한 설명을 남겨주세요.

3. 추가로 동작한 스프링 부트 버전과 동작하지 않은 스프링 부트 버전도 같이 남겨주세요.

감사합니다.

 

0

jumong님의 프로필 이미지
jumong
질문자

안녕하세요 매번 번거롭게 해서 죄송합니다.

 

findByHeadIdxAndAIdxNot  -> findByHeadIdxAndaIdxNot 으로 바뀌면서

No property andaIdx found for type Integer! Traversed path: Article.headIdx.

이러한 문구로 에러를 발생시킵니다

 

그전에는 문제 없이 되던 것이 스프링 부트, gradle버전 올렸습니다.

그리고 수정한 것이라고는 @Autowired 주입을 @RequiredArgsConstructor으로 수정을 하면서

발생을 했습니다.

 

0

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. jumong님

자바빈 프로퍼티 문법에서 첫글짜가 소문자이고, 두번째가 바로 대문자이면 혼란이 올 수 있습니다.

aIdx, bIdx처럼요.

이 경우 다음과 같이 고쳐서 사용해주세요.

다음 스프링 데이터 JPA의 메서드들을 고치시면 될꺼에요.

findByAIdx() -> findByaIdx()

감사합니다.

0

jumong님의 프로필 이미지
jumong
질문자

안녕하세요

동일한 에러가 발생하고 있습니다.

해결을 해야 하는데 어떻게 하면 될 수 있을지요?

0

jumong님의 프로필 이미지
jumong
질문자

안녕하세요. 답변 감사합니다 그런데

Article 클래스의 AIdx에 해당하는 필드명이 아래

이렇게 되어 있는데 어디가 문제가 있을까요 

aIdx위의 @Column 어노테이션 삭제해도 동일한 에러가 발생하나요?

0

안녕하세요. jumong님, 공식 서포터즈 OMG입니다.

Article 클래스의 AIdx에 해당하는 필드명을 매핑 실패로 보입니다.

Article 클래스에 aIdx 필드(대소문자 구분)를 추가해주세요.

 

findByHeadIdxAndAIdxNot

 

참고

JPA 오류 해결 - Unable to locate Attribute with the the given name [Column] (tistory.com)

감사합니다.

jumong님의 프로필 이미지
jumong

작성한 질문수

질문하기