问题描述
将项目 spring boot 从 2.0.5.RELEASE 升级到 2.1.18.RELEASE 并将 spring 框架从 5.0.9.RELEASE 升级到 5.1.20.RELEASE 后,应用程序在启动时遇到 UnsatisfiedDependencyException:
“调用 init 方法失败;嵌套异常为 java.lang.IllegalStateException:您已在存储库中定义了查询方法,但未定义任何查询查找策略。基础结构显然不支持查询方法!”
本项目使用 redis 作为持久化与 spring-data-redis 和 spring-data-jpa 与 sql Server。以及Redis存储库实现查询方法:
@EnableAspectJAutoproxy
@PropertySource("classpath:/application.properties")
@PropertySource(value = "classpath:application-${project_env:default}.properties",ignoreResourceNotFound = true)
@PropertySource(value = "file:/project/application.properties",ignoreResourceNotFound = true)
@EnableRedisRepositories("project.repository.redis")
@Configuration
public class MainConfiguration { }
package project.repository.redis;
import project.domain.redis.hash.SessionRegistry;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
public interface ProjectRedisRepository extends CrudRepository<SessionRegistry,String> {
SessionRegistry findBySessionKey(String sessionKey);
}
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.index.Indexed;
import project.domain.enums.SessionStatus;
@RedisHash(timetoLive = 120)
public class SessionRegistry {
@Id
private String id;
@Indexed
private String sessionKey;
private SessionStatus status;
private String token;
public SessionRegistry() {
}
...getters and setters...
build.gradle
dependencies {
...
// In case of Database use
compile "org.springframework.boot:spring-boot-starter-data-jpa:2.1.18.RELEASE"
compile "org.springframework:spring-jdbc:5.1.20.RELEASE"
runtime "com.microsoft.sqlserver:mssql-jdbc:9.1.0.jre11-preview"
compile "com.zaxxer:HikariCP:3.1.0" // connection pool
...
此错误仅在存储库具有查询方法时发生。如果我们使用默认的 CrudRepository 方法,就没有问题。
依赖:
| +--- org.springframework.boot:spring-boot:2.0.6.RELEASE -> 2.1.18.RELEASE (*)
| +--- org.springframework.boot:spring-boot-starter-data-redis:2.0.4.RELEASE -> 2.1.18.RELEASE
| | +--- org.springframework.boot:spring-boot-starter:2.1.18.RELEASE (*)
| | +--- org.springframework.data:spring-data-redis:2.1.21.RELEASE
| | | +--- org.springframework.data:spring-data-keyvalue:2.1.21.RELEASE
| | | | +--- org.springframework.data:spring-data-commons:2.1.21.RELEASE (*)
| +--- org.springframework.data:spring-data-jpa:2.1.21.RELEASE
| | +--- org.springframework.data:spring-data-commons:2.1.21.RELEASE
| | | +--- org.springframework:spring-core:5.1.19.RELEASE (*)
| | | +--- org.springframework:spring-beans:5.1.19.RELEASE (*)
降级 由于 Cloud Open Feing 依赖项升级和兼容性,Spring Boot 和 Spring Framework 不适合此项目。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)