๐Ÿšซ ์—๋Ÿฌ ์ƒํ™ฉ

Redis ๋‚ด์˜ Refresh token ๊ฐ’์„ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•ด CrudRepository ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , RDBMS ๋‚ด์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•ด JpaRepository ๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋œจ๋Š” ์—ฌ๋Ÿฌ ๋กœ๊ทธ ์ค‘ ์—๋Ÿฌ๋Š” ์•„๋‹ˆ์ง€๋งŒ, ๋ฐ˜๊ฐ‘์ง€ ์•Š์€ INFO ๋กœ๊ทธ๊ฐ€ 2๊ฐœ์˜ ์˜์—ญ์œผ๋กœ ๋‚˜๋‰˜์–ด 7๊ฐœ ์ •๋„ ๋ฐ˜๋ณต๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค. ์—”ํ‹ฐํ‹ฐ ํด๋ž˜์Šค ์ˆ˜ ๋งŒํผ ๋ฐ˜๋ณต ๋˜์—ˆ๊ณ , ์•„๋ž˜์ฒ˜๋Ÿผ ๋กœ๊ทธ๊ฐ€ ์ถœ๋ ฅ๋์Šต๋‹ˆ๋‹ค.

  • A ์˜์—ญ: Spring Data JPA
2023-06-18 19:10:30.731  INFO 4986 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2023-06-18 19:10:30.670  INFO 4986 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data JPA - Could not safely identify store assignment for repository candidate interface jparest.practice.auth.jwt.RefreshTokenRepository; If you want this repository to be a JPA repository, consider annotating your entities with one of these annotations: javax.persistence.Entity, javax.persistence.MappedSuperclass (preferred), or consider extending one of the following types with your repository: org.springframework.data.jpa.repository.JpaRepository
  • B ์˜์—ญ: Spring Data Redis
2023-06-18 19:10:30.741  INFO 4986 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface jparest.practice.group.repository.GroupRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2023-06-18 19:10:30.741  INFO 4986 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface jparest.practice.group.repository.UserGroupRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2023-06-18 19:10:30.741  INFO 4986 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface jparest.practice.invite.repository.InviteRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2023-06-18 19:10:30.741  INFO 4986 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface jparest.practice.rest.repository.GroupRestRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2023-06-18 19:10:30.742  INFO 4986 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface jparest.practice.rest.repository.RestRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2023-06-18 19:10:30.742  INFO 4986 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface jparest.practice.user.repository.UserRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository

๋กœ๊ทธ๋Š” ๋‘๊ฐœ์˜ ์˜์—ญ์œผ๋กœ ๋‚˜๋‰˜์—ˆ๊ณ , ์ฝ์–ด๋ณด๋ฉด

โ€œSpring Data JPA: ์—”ํ‹ฐํ‹ฐ์˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ๋Œ€ํ•ด ์‹๋ณ„ํ•  ์ˆ˜ ์—†๋‹ค. ๋งŒ์•ฝ ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ JPA repository๋กœ ๋งŒ๋“ค๋ ค๋ฉด @Entity ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•ด๋ผโ€

โ€œSpring Data Redis: ์—”ํ‹ฐํ‹ฐ์˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ๋Œ€ํ•ด ์‹๋ณ„ํ•  ์ˆ˜ ์—†๋‹ค. ๋งŒ์•ฝ ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ Redis repository๋กœ ๋งŒ๋“ค๋ ค๋ฉด @RedisHash ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•ด๋ผโ€

์ด๋Ÿฐ ๋‚ด์šฉ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์™œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์‹๋ณ„ํ•  ์ˆ˜ ์—†๋Š”์ง€ ์˜๋ฌธ์ด์—ˆ์Šต๋‹ˆ๋‹ค.


๐Ÿ“œ ์—๋Ÿฌ ์›์ธ

JpaRepository, CrudRepository ๋Š” ๋ชจ๋‘ Repository ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ™•์žฅํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋ฌธ์ œ๋Š” @Entity ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  Respository ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉ(Redis ์˜ ๊ฒฝ์šฐ)ํ–ˆ์„ ๋•Œ, Spring ์ด โ€™Repository ๋กœ๋ถ€ํ„ฐ ์ƒ์„ฑ๋œ ๋ฉ”์„œ๋“œ๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜์ง€?โ€™ ํ•˜๊ณ  ์˜๋ฌธ์„ ํ’ˆ๊ณ  ์Šค์Šค๋กœ ์ฐพ๋Š”๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ, ์•„๋ž˜์ฒ˜๋Ÿผ Redis ์—์„œ CrudRepository ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  @Entity ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜์œผ๋ฏ€๋กœ Spring์€ ๊ฐ Repository ์˜ ๋ฉ”์„œ๋“œ ๋“ค์„ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ•ด์•ผํ•˜๋Š” ์ง€ ์ฐพ์Šต๋‹ˆ๋‹ค.

package jparest.practice.auth.jwt;

...

@Getter
@RedisHash("refresh")
@NoArgsConstructor
public class RefreshToken {

    @Id
    private String id;

    private String refreshToken;

    ...
}
public interface RefreshTokenRepository extends CrudRepository<RefreshToken, String> {
}

๊ทธ๋Ÿฌํ•œ ํƒ์ƒ‰ ๊ณผ์ •์ด (JpaRepository x N) + (CrudRepository x M) ๋งŒํผ ์ด๋ฃจ์–ด์ง„๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค. (์ถ”์ธก์ž…๋‹ˆ๋‹ค.)


๐Ÿ”‘ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

1. EnableRedisRepositories ์ถ”๊ฐ€

package jparest.practice.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

@Configuration
@EnableRedisRepositories(basePackages = "jparest.practice.auth.jwt")
public class RedisConfig {
}

EnableRedisRepositories ์–ด๋…ธํ…Œ์ด์…˜ ์„ ์ด์šฉํ•˜๋ฉด, RedisRepository ๋ฅผ ํ™œ์„ฑํ™” ์‹œํ‚ค๊ณ , ๋นˆ ์Šค์บ๋‹ ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์ง€์ •ํ•ด์ฃผ๋‹ˆ RedisRepository ์— ๋Œ€ํ•œ ํƒ์ƒ‰์„ ๋‹ค๋ฅธ ๊ฒฝ๋กœํ•ด์„œ ํ•˜์ง€ ์•Š์•„์„œ B ์˜์—ญ ๋กœ๊ทธ๊ฐ€ ์ถœ๋ ฅ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.


2. EnableJpaRepositories ์ถ”๊ฐ€

package jparest.practice.common.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration
@EnableJpaRepositories(basePackages = "jparest.practice",
        excludeFilters = @ComponentScan.Filter(
                type = FilterType.ASPECTJ, pattern = "jparest.practice.auth.jwt.*"
        )
)
public class JpaConfig {
}

์—ฌ์ „ํžˆ A ๋กœ๊ทธ๋Š” ์ถœ๋ ฅ๋์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ JpaRepository ๋ฅผ ํ™œ์„ฑํ™” ์‹œํ‚ค๊ณ , ๋นˆ ์Šค์บ๋‹ ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด ์ถ”๊ฐ€ EnableJpaRepositories ์–ด๋…ธํ…Œ์ด์…˜์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฃผ์˜ํ•  ์ ์€ @Entity ๊ฐ€ ์—†๋Š”๋ฐ Repository ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด Spring ์ด ์–ด๋–ป๊ฒŒ ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•  ์ง€ ์ฐพ๋Š”๋‹ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ Redis ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ณณ์€ ๋นˆ ์Šค์บ๋‹ ๋ฒ”์œ„์—์„œ ์ œ์™ธ์‹œ์ผฐ์Šต๋‹ˆ๋‹ค. EnableJpaRepositories ๊นŒ์ง€ ์ ์šฉํ–ˆ๋”๋‹ˆ ๋ชจ๋“  ๋กœ๊ทธ๊ฐ€ ์‚ฌ๋ผ์ง„ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

2023-06-18 20:42:02.762  INFO 5431 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 141 ms. Found 6 JPA repository interfaces.
2023-06-18 20:42:02.763  INFO 5431 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2023-06-18 20:42:02.763  INFO 5431 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2023-06-18 20:42:02.772  INFO 5431 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 3 ms. Found 1 Redis repository interfaces.

์ฐธ๊ณ  ์ž๋ฃŒ

https://stackoverflow.com/questions/47002094/spring-multiple-spring-data-modules-found-entering-strict-repository-configur