Redis Query-by-Example supports only case-sensitive matching

engourdi 2019-04-14 11:31:43
用springboot整合redis和jpa爆的错,数据库mysql
配置
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xx?useunicode=true&characterEncoding=utf8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=xx
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.max-idle=60
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
# Specify the DBMS
spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = none
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.main.allow-bean-definition-overriding=true
# \load all-endpoint/ default info / health
management.endpoints.web.exposure.include=*
#redis
spring.redis.host=127.0.0.1
spring.redis.password=xx
spring.redis.lettuce.pool.maxActive=5
spring.redis.lettuce.pool.maxIdle=5


代码:

public interface MyRedisUserRepository extends CrudRepository<User, Long>{
Optional<User> findOneByPhone(String phone);
//Optional<User> findOneByEmail(String email);
}

public interface MysqlUserRepository extends JpaRepository<User, Long>{

}
@Slf4j
@Service
@Transactional
public class UserService {
@Autowired
MysqlUserRepository mysqlUserRepository;
@Autowired
MyRedisUserRepository myRedisUserRepository;
public Optional<User> findUserByPhone(String phone){
Optional<User> catched = myRedisUserRepository.findOneByPhone(phone);
if(catched.isPresent()) {
User user = catched.get();
log.info("user {} found in cache.",user);
return Optional.of(user);
}else {
Optional<User> raw = findOneUserByPhone(phone);
raw.ifPresent(c->{
myRedisUserRepository.save(c);
});
return raw;
}
}
public Optional<User> findOneUserByPhone(String phone){
ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("phone", exact().ignoreCase());
Optional<User> user = mysqlUserRepository.findOne(Example.of(User.builder().phone(phone).build(),matcher));
log.info("user found in sql:{}",user);
return user;
}
public Optional<User> saveUser2Sql(User user){
user = mysqlUserRepository.save(user);
return Optional.of(user);
}
}
@SpringBootApplication
@Slf4j
@EnableJpaRepositories
@EnableRedisRepositories
public class MybootApplication implements ApplicationRunner{
@Autowired
private UserService userService;
public static void main(String[] args) {
SpringApplication.run(MybootApplication.class, args);
}

@Override
public void run(ApplicationArguments args) throws Exception {
// Optional<User> u = userService.findUserByPhone("xxxx");
// log.info("user {}",u);
// userService.findAllUser();
User user = User.builder().phone("xxxxx").name("xx").city("xx").email("xx@126.com").build();
// userService.saveUser(user);
// userService.findUserByPhone("xxx");
log.info("user {}",user);
userService.saveUser2Sql(user);
log.info("user {}",user);
log.info("user {}",userService.findOneUserByPhone("xxxx").get());
//userService.findUserByEmail("engourdi@126.com");
}

}

@Entity
@Builder
@RedisHash(value = "myboot-user", timeToLive = 2592000)
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "user")
public @Data class User implements Serializable{
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private Integer id;
private String name;
private String phone;
private String email;
private String password;
}

异常日志:

java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:807) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:794) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at com.franklin.myboot.MybootApplication.main(MybootApplication.java:28) [classes/:na]
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Redis Query-by-Example supports only case-sensitive matching.
at org.springframework.data.redis.repository.query.ExampleQueryMapper.applyPropertySpec(ExampleQueryMapper.java:137) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.redis.repository.query.ExampleQueryMapper.lambda$applyPropertySpecs$0(ExampleQueryMapper.java:118) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at java.lang.Iterable.forEach(Unknown Source) ~[na:1.8.0_161]
at org.springframework.data.redis.repository.query.ExampleQueryMapper.applyPropertySpecs(ExampleQueryMapper.java:106) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.redis.repository.query.ExampleQueryMapper.getMappedExample(ExampleQueryMapper.java:88) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.redis.repository.support.QueryByExampleRedisExecutor.createQuery(QueryByExampleRedisExecutor.java:187) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.redis.repository.support.QueryByExampleRedisExecutor.findOne(QueryByExampleRedisExecutor.java:97) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_161]
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at com.sun.proxy.$Proxy113.findOne(Unknown Source) ~[na:na]
at com.franklin.myboot.service.UserService.findOneUserByPhone(UserService.java:55) ~[classes/:na]
at com.franklin.myboot.service.UserService$$FastClassBySpringCGLIB$$322924e3.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.spri
...全文
278 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
engourdi 2019-04-14
  • 打赏
  • 举报
回复
自己蠢了,把springcache的标注和jpa的混在一起了,改了以后就ok了
内容概要:本文系统介绍了基于核主成分分析(KPCA)的故障检测方法,重点实现了T²和Q统计指数的可视化,并提供了完整的Matlab代码实现与仿真分析流程。该方法通过核函数映射将原始非线性过程数据转换至高维特征空间,进行主成分提取与降维处理,进而构建T²和Q两种统计量用于监控系统运行状态,有效识别工业过程中的早期故障与异常行为。文中详细阐述了KPCA的数学原理、故障检测机制、控制限计算方法,并结合实际案例展示其在复杂非线性系统中的应用效果与优越性,具有较强的工程实用性。; 适合人群:具备一定信号处理、机器学习理论基础及Matlab编程能力的研究生、科研人员和工程技术人员,特别适用于从事工业过程监控、故障诊断、智能制造等相关领域的研究人员。; 使用场景及目标:①应用于化工、电力、制造等行业中关键设备的在线故障监测与早期预警;②作为学术研究中非线性降维与异常检测算法的对比基准;③帮助开发者掌握KPCA模型构建、参数调优及T²-Q统计图可视化等核心技术环节。; 阅读建议:建议读者结合所提供的Matlab代码进行动手实践,深入理解KPCA算法的核心步骤,重点关注核函数选择、主成分数确定及统计量阈值设定等关键参数的影响,以提升故障检测的灵敏度与准确性。

67,535

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧