Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-04-13 23:07:15.360 ERROR 102144 --- [           main] o.s.boot.SpringApplication               : Application run failed

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:85) ~[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.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at com.franklin.myboot.service.UserService$$EnhancerBySpringCGLIB$$9c6b0c5f.findOneUserByPhone(<generated>) ~[classes/:na]
    at com.franklin.myboot.MybootApplication.run(MybootApplication.java:42) [classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]

my code is follow:

    @Slf4j
    @Service
    @Transactional

public class UserService {
    @Autowired 
    MysqlUserRepository mysqlUserRepository;
    @Autowired 
    MyRedisUserRepository myRedisUserRepository;

public List<User> findAllUser(){
    return mysqlUserRepository.findAll();
}

/**
 * this is a cached func
 * @param phone
 * @return
 */
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;
}
enter code here

my config:

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/hj?useunicode=true&characterEncoding=utf8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=franklin
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=franklin
spring.redis.lettuce.pool.maxActive=5
spring.redis.lettuce.pool.maxIdle=5          

0 Answers