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

tjdwnsdks님의 프로필 이미지
tjdwnsdks

작성한 질문수

코드로 배우는 React with 스프링부트 API서버

질문1) 'Querydsl 검색처리'의 TDD 에서 에러가 나는데 도저히 모르겠습니다..

작성

·

51

·

수정됨

0

안녕하세요.

그런데 섹션3 의 'Querydsl 검색처리' 영상을 다 보고 TDD 테스트를 돌리는데 계속 아래와 같은 에러가 납니다.. 몇일동안 찾아봤는데도 아예 해결이 되지 않아서 여기에 질문드리게 됐네요.. ㅠㅠ

혹시 몰라 콘솔탭에 있는거 전부 다 복사해 왔습니다.

강의를 파트별로 정리하면서 공부하고 있어서 앞에 Ex01 이런식으로 이름이 붙어 있습니다.

왜 안되는지 도저히 모르겠어요..

(게시글이 10000자 이상 안써진다고 해서 댓글에 다음 메세지들 쓰겠습니다.)

(혹시 몰라서 대댓글로 코드들도 남깁니다.)


   .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.3.6)

 2024-12-02T05:13:22.977+09:00  INFO 7780 --- [  restartedMain] c.zerock.apiserver.ApiserverApplication  : Starting ApiserverApplication using Java 17.0.13 with PID 7780 (C:\Users\hykim\Desktop\apiserver\build\classes\java\main started by hykim in C:\Users\hykim\Desktop\apiserver)

2024-12-02T05:13:22.993+09:00  INFO 7780 --- [  restartedMain] c.zerock.apiserver.ApiserverApplication  : No active profile set, falling back to 1 default profile: "default"

2024-12-02T05:13:23.010+09:00  INFO 7780 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable

2024-12-02T05:13:23.010+09:00  INFO 7780 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'

2024-12-02T05:13:23.322+09:00  INFO 7780 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.

2024-12-02T05:13:23.353+09:00  INFO 7780 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 28 ms. Found 1 JPA repository interface.

2024-12-02T05:13:23.632+09:00  INFO 7780 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)

2024-12-02T05:13:23.638+09:00  INFO 7780 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

2024-12-02T05:13:23.638+09:00  INFO 7780 --- [  restartedMain] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.33]

2024-12-02T05:13:23.665+09:00  INFO 7780 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

2024-12-02T05:13:23.665+09:00  INFO 7780 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 655 ms

2024-12-02T05:13:23.733+09:00  INFO 7780 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]

2024-12-02T05:13:23.761+09:00  INFO 7780 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.5.3.Final

2024-12-02T05:13:23.777+09:00  INFO 7780 --- [  restartedMain] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled

2024-12-02T05:13:23.936+09:00  INFO 7780 --- [  restartedMain] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer

2024-12-02T05:13:23.951+09:00  INFO 7780 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...

2024-12-02T05:13:23.989+09:00  INFO 7780 --- [  restartedMain] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.mariadb.jdbc.Connection@6303bda2

2024-12-02T05:13:23.990+09:00  INFO 7780 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.

2024-12-02T05:13:24.411+09:00  INFO 7780 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)

2024-12-02T05:13:24.438+09:00  INFO 7780 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'

2024-12-02T05:13:24.535+09:00  WARN 7780 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ex04_10_TodoServiceImpl' defined in file [C:\Users\hykim\Desktop\apiserver\build\classes\java\main\com\zerock\apiserver\service\Ex04_10_TodoServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'ex04_13_TodoRepository' defined in com.zerock.apiserver.repository.Ex04_13_TodoRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto); Reason: Paging query needs to have a Pageable parameter; Offending method: public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto)

2024-12-02T05:13:24.535+09:00  INFO 7780 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'

2024-12-02T05:13:24.537+09:00  INFO 7780 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...

2024-12-02T05:13:24.538+09:00  INFO 7780 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

2024-12-02T05:13:24.539+09:00  INFO 7780 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

2024-12-02T05:13:24.545+09:00  INFO 7780 --- [  restartedMain] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.

2024-12-02T05:13:24.556+09:00 ERROR 7780 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ex04_10_TodoServiceImpl' defined in file [C:\Users\hykim\Desktop\apiserver\build\classes\java\main\com\zerock\apiserver\service\Ex04_10_TodoServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'ex04_13_TodoRepository' defined in com.zerock.apiserver.repository.Ex04_13_TodoRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto); Reason: Paging query needs to have a Pageable parameter; Offending method: public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto)

	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:795) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:237) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1375) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1212) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) ~[spring-context-6.1.15.jar:6.1.15]

	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[spring-context-6.1.15.jar:6.1.15]

	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.3.6.jar:3.3.6]

	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.6.jar:3.3.6]

	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.6.jar:3.3.6]

	at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.6.jar:3.3.6]

	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.6.jar:3.3.6]

답변 2

0

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

본문 글 이어서 메세지 남깁니다.

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.6.jar:3.3.6]

	at com.zerock.apiserver.ApiserverApplication.main(ApiserverApplication.java:10) ~[main/:na] 
    
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]

	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]

	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.3.6.jar:3.3.6]

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ex04_13_TodoRepository' defined in com.zerock.apiserver.repository.Ex04_13_TodoRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto); Reason: Paging query needs to have a Pageable parameter; Offending method: public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto)

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1806) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1443) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:904) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:782) ~[spring-beans-6.1.15.jar:6.1.15]

	... 24 common frames omitted

Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto); Reason: Paging query needs to have a Pageable parameter; Offending method: public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto)

	at org.springframework.data.repository.query.QueryCreationException.create(QueryCreationException.java:101) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:119) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.mapMethodsToQuery(QueryExecutorMethodInterceptor.java:103) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$new$0(QueryExecutorMethodInterceptor.java:92) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at java.base/java.util.Optional.map(Optional.java:260) ~[na:na]

	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.<init>(QueryExecutorMethodInterceptor.java:92) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:357) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:290) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.util.Lazy.getNullable(Lazy.java:135) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.util.Lazy.get(Lazy.java:113) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:296) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:132) ~[spring-data-jpa-3.3.6.jar:3.3.6]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-6.1.15.jar:6.1.15]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1802) ~[spring-beans-6.1.15.jar:6.1.15]

	... 35 common frames omitted

Caused by: java.lang.IllegalArgumentException: Paging query needs to have a Pageable parameter; Offending method: public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto)

	at org.springframework.util.Assert.isTrue(Assert.java:111) ~[spring-core-6.1.15.jar:6.1.15]

	at org.springframework.data.repository.query.QueryMethod.validate(QueryMethod.java:130) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:103) ~[spring-data-commons-3.3.6.jar:3.3.6]

	at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:116) ~[spring-data-jpa-3.3.6.jar:3.3.6]

	at org.springframework.data.jpa.repository.query.DefaultJpaQueryMethodFactory.build(DefaultJpaQueryMethodFactory.java:44) ~[spring-data-jpa-3.3.6.jar:3.3.6]

	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:94) ~[spring-data-jpa-3.3.6.jar:3.3.6]

	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:115) ~[spring-data-commons-3.3.6.jar:3.3.6]

	... 47 common frames omitted
tjdwnsdks님의 프로필 이미지
tjdwnsdks
질문자

혹시 몰라서 코드들도 올립니다.

= Ex01_Todo =

package com.zerock.apiserver.domain;

import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;

@Entity
@ToString
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name="tbl_todo")
public class Ex01_Todo {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long tno;

    @Column(length = 500, nullable = false)
    private String title;

    private String content;

    private boolean complete;

    private LocalDate dueDate;

    public void setTno(Long tno) {
        this.tno = tno;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setComplete(boolean complete) {
        this.complete = complete;
    }

    public void setDueDate(LocalDate dueDate) {
        this.dueDate = dueDate;
    }
} 

 

= Ex04_1_TodoDto=

package com.zerock.apiserver.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Ex04_1_TodoDto {
    private Long tno; 

    private String title; 

    private String content; 

    private boolean complete; 

    private LocalDate dueDate; 
}

 

= Ex04_7_PageRequestDto=

package com.zerock.apiserver.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder  
@AllArgsConstructor
@NoArgsConstructor
public class Ex04_7_PageRequestDto {
    @Builder.Default    
    private int page = 1;

    @Builder.Default
    private int size = 10;
}

 

= Ex04_8_PageResponseDTO=

package com.zerock.apiserver.dto;

import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Data
public class Ex04_8_PageResponseDTO<E> {
  private List<E> dtoList;

  private List<Integer> pageNumList;

  private Ex04_7_PageRequestDto pageRequestDTO;

  private boolean prev, next;

  private int totalCount, prevPage, nextPage, totalPage, current;

  @Builder(builderMethodName = "withAll")
  public Ex04_8_PageResponseDTO(List<E> dtoList, Ex04_7_PageRequestDto pageRequestDTO, long totalCount) {

    this.dtoList = dtoList;
    this.pageRequestDTO = pageRequestDTO;
    this.totalCount = (int)totalCount;

    int end =   (int)(Math.ceil( pageRequestDTO.getPage() / 10.0 )) *  10;

    int start = end - 9;

    int last =  (int)(Math.ceil((totalCount/(double)pageRequestDTO.getSize())));

    end =  end > last ? last: end;

    this.prev = start > 1;

    this.next =  totalCount > end * pageRequestDTO.getSize();

    this.pageNumList = IntStream.rangeClosed(start,end).boxed().collect(Collectors.toList());


    this.prevPage = prev? start-1 : 0;


    this.nextPage = next? end+1 : 0;

    this.totalPage = this.pageNumList.size();
  }
}


= Ex04_11_TodoSearch=

package com.zerock.apiserver.repository.search;

import com.zerock.apiserver.domain.Ex01_Todo;
import com.zerock.apiserver.dto.Ex04_7_PageRequestDto;
import org.springframework.data.domain.Page; 

public interface Ex04_11_TodoSearch {
    Page<Ex01_Todo> search1(Ex04_7_PageRequestDto pageRequestDto);
} 


= Ex04_12_TodoSearchImpl=

package com.zerock.apiserver.repository.search;

import com.querydsl.jpa.JPQLQuery;
import com.zerock.apiserver.domain.Ex01_Todo;
import com.zerock.apiserver.domain.QEx01_Todo;
import com.zerock.apiserver.dto.Ex04_7_PageRequestDto;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;

import java.util.List;

@Log4j2
public class Ex04_12_TodoSearchImpl extends QuerydslRepositorySupport implements Ex04_11_TodoSearch {

    public Ex04_12_TodoSearchImpl() {
        super(Ex01_Todo.class); // 도메인 클래스 지정
    }

    @Override
    public Page<Ex01_Todo> search1(Ex04_7_PageRequestDto pageRequestDto) {

        log.info("search1............");

        QEx01_Todo todo = QEx01_Todo.ex01_Todo; 
        JPQLQuery<Ex01_Todo> query = from(todo); 

        //query.where(todo.title.contains("1")); 

        //Pageable pageable = PageRequest.of(1,10, Sort.by("tno").descending());
        Pageable pageable = PageRequest.of(pageRequestDto.getPage()-1,
                pageRequestDto.getSize(),
                Sort.by("tno").descending());

        this.getQuerydsl().applyPagination(pageable, query);
        List<Ex01_Todo> list = query.fetch(); 
        long total = query.fetchCount(); 

        return new PageImpl<>(list, pageable, total);

    }
}


= Ex04_13_TodoRepository=

package com.zerock.apiserver.repository;


import com.zerock.apiserver.domain.Ex01_Todo;
import com.zerock.apiserver.repository.search.Ex04_11_TodoSearch;
import org.springframework.data.jpa.repository.JpaRepository;

public interface Ex04_13_TodoRepository extends JpaRepository<Ex01_Todo, Long>, Ex04_11_TodoSearch {
}


= Ex04_9_TodoService=

package com.zerock.apiserver.service;

import com.zerock.apiserver.domain.Ex01_Todo;

import com.zerock.apiserver.dto.Ex04_1_TodoDto;
import com.zerock.apiserver.dto.Ex04_7_PageRequestDto;
import com.zerock.apiserver.dto.Ex04_8_PageResponseDTO;
import jakarta.transaction.Transactional;

@Transactional
public interface Ex04_9_TodoService {
    Ex04_1_TodoDto get(Long tno);

    // 등록
    Long register(Ex04_1_TodoDto todoDTO);

    // 수정
    void modify(Ex04_1_TodoDto todoDTO);

    // 삭제
    void remove(Long tno);

    Ex04_8_PageResponseDTO<Ex04_1_TodoDto> getList(Ex04_7_PageRequestDto pageRequestDto);

    default Ex04_1_TodoDto entityToDTO(Ex01_Todo todo) {
        Ex04_1_TodoDto todoDto = Ex04_1_TodoDto.builder()
                .tno(todo.getTno())
                .title(todo.getTitle())
                .content(todo.getContent())
                .complete(todo.isComplete())
                .dueDate(todo.getDueDate())
                .build();

        return todoDto;
    }

    default Ex01_Todo dtoToEntity(Ex04_1_TodoDto todoDto) {
        Ex01_Todo todo = Ex01_Todo.builder()
                .tno(todoDto.getTno())
                .title(todoDto.getTitle())
                .content(todoDto.getContent())
                .complete(todoDto.isComplete())
                .dueDate(todoDto.getDueDate())
                .build();

        return todo;
    }
}


= Ex04_10_TodoServiceImpl=

package com.zerock.apiserver.service;


import com.zerock.apiserver.domain.Ex01_Todo;
import com.zerock.apiserver.dto.Ex04_1_TodoDto;
import com.zerock.apiserver.dto.Ex04_7_PageRequestDto;
import com.zerock.apiserver.dto.Ex04_8_PageResponseDTO;
import com.zerock.apiserver.repository.Ex04_13_TodoRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@Log4j2
@RequiredArgsConstructor
public class Ex04_10_TodoServiceImpl implements Ex04_9_TodoService {
    private final Ex04_13_TodoRepository todoRepository;

    @Override
    public Ex04_1_TodoDto get(Long tno) {
        Optional<Ex01_Todo> result = todoRepository.findById(tno);
        Ex01_Todo todo = result.orElseThrow();
        return entityToDTO(todo);
    }

    @Override
    public Long register(Ex04_1_TodoDto todoDTO) {

        Ex01_Todo todo = dtoToEntity(todoDTO);
        Ex01_Todo result =  todoRepository.save(todo);

        return result.getTno();
    }

    @Override
    public void modify(Ex04_1_TodoDto dto) {
        Optional<Ex01_Todo> result = todoRepository.findById(dto.getTno());
        Ex01_Todo todo = result.orElseThrow();

        todo.setTitle(dto.getTitle());
        todo.setContent(dto.getContent());
        todo.setComplete(dto.isComplete());
        todo.setDueDate(dto.getDueDate());

        todoRepository.save(todo);
    }

    @Override
    public void remove(Long tno) {
        todoRepository.deleteById(tno);
    }

    @Override
    public Ex04_8_PageResponseDTO<Ex04_1_TodoDto> getList(Ex04_7_PageRequestDto pageRequestDto) {
        Page<Ex01_Todo> result = todoRepository.search1(pageRequestDto);


        List<Ex04_1_TodoDto> dtoList = result
                .get()
                .map(todo -> entityToDTO(todo) )
                .collect(Collectors.toList());


        Ex04_8_PageResponseDTO<Ex04_1_TodoDto> responseDTO =
                Ex04_8_PageResponseDTO.<Ex04_1_TodoDto>withAll() /* (withAll 은 PageResponseDTO 에 있음)*/
                        .dtoList(dtoList)
                        .pageRequestDTO(pageRequestDto)
                        .totalCount(result.getTotalElements())
                        .build();

        return responseDTO;
    }

}


 

 

구멍가게코딩단님의 프로필 이미지
구멍가게코딩단
지식공유자

일단 에러 메시지의 핵심은

 

Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto); Reason: Paging query needs to have a Pageable parameter; Offending method: public abstract org.springframework.data.domain.Page com.zerock.apiserver.repository.search.Ex04_11_TodoSearch.search1(com.zerock.apiserver.dto.Ex04_7_PageRequestDto)

 

부분이네요..

 

우선 Querydsl의 인터페이스와 구현클래스는 이름이 일치해야만 합니다.

 

Ex04_11_TodoSearch

 

Ex04_11_TodoSearchImpl

 

로 되어야 합니다.

 

 

코드는

 

https://drive.google.com/drive/folders/1ZLHRKaXx8Ou8kZNd1WE6qALxq_wJODXW?usp=drive_link

 

로 프로젝트 자체를 압축해서 올려주세요

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

강사님 공유 권한이 없다고 나와요.. 권한 풀어주실수 있을까요?

아니시면 혹시 몰라서 급한대로 제 드라이브에 압축해서 올려놨습니다. (아래 링크)

https://drive.google.com/drive/folders/1TQxdqkRD8xvXIHzVoI5fp2hm_HZaE0aT

 

내일쯤 답 주실줄 알았는데 빠른 답변 감사합니다. ㅠㅠ

구멍가게코딩단님의 프로필 이미지
구멍가게코딩단
지식공유자

올려주신 코드 확인하고 댓글 남기겠습니다.

구멍가게코딩단님의 프로필 이미지
구멍가게코딩단
지식공유자

0185.jpg.webp

와 같이 파일명을 수정해 보세요

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

와 대박! 강사님 되요!!!

전 3일동안 밤새가면서 검색해도 못고쳤었는데...

Querydsl의 인터페이스와 구현클래스는 이름이 같아야 한다라는거였다니..

진짜진짜 감사합니다!!

좋은하루 보내세요.

0

안녕하세요, 인프런 AI 인턴입니다.

tjdwnsdks님, ‘Querydsl 검색처리’ 관련 TDD 테스트 수행 중 발생한 에러로 인해 어려움을 겪고 계시네요. 해당 에러는 Paging query needs to have a Pageable parameter 라는 메시지를 기반으로 Spring Data JPA에서 PagingQuery를 사용할 때 Pageable 파라미터가 필요하다는 것을 나타냅니다.

비슷한 오류와 해결 방법을 다룬 답변을 찾았습니다. 아래 링크를 통해 확인해 보세요.

  1. Spring Boot에서 Pageable 사용 오류 해결하기
    이 질문에서 언급된 에러는 특정 메소드를 사용할 때 필요한 파라미터와 관련된 것으로, 해결 방법을 통해 유사한 문제의 해결 방안을 얻을 수 있습니다.

위의 링크가 도움이 되시길 바라며, 추가적으로 명확한 해결책을 위한 몇 가지 조언을 드리자면:
- Ex04_11_TodoSearch.search1 메소드의 파라미터에 Pageable 형식의 인자가 포함되어 있는지 확인해보세요.
- Querydsl 설정 및 의존성 관련 문제가 없는지 재점검해보세요.

프로젝트 설정 중 발생할 수 있는 일반적인 문제와 해결 방안을 확인할 수 있는 답변들이니, 참고하여 문제 해결에 도움이 되길 바랍니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

tjdwnsdks님의 프로필 이미지
tjdwnsdks

작성한 질문수

질문하기