尝试将 StringMatcher.REGEX 与 java spring 一起使用时出现问题。没有编译器错误或任何东西,但是当您尝试使用上述字符串匹配器调用该项目时,您会收到以下错误:
2020-10-09 15:07:30.543 ERROR 29584 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Unsupported StringMatcher REGEX; nested exception is java.lang.IllegalArgumentException: Unsupported StringMatcher REGEX] with root cause
java.lang.IllegalArgumentException: Unsupported StringMatcher REGEX
at org.springframework.data.jpa.convert.QueryByExamplePredicateBuilder.getPredicates(QueryByExamplePredicateBuilder.java:210) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.data.jpa.convert.QueryByExamplePredicateBuilder.getPredicate(QueryByExamplePredicateBuilder.java:102) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.data.jpa.repository.support.SimpleJpaRepository$ExampleSpecification.toPredicate(SimpleJpaRepository.java:886) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.applySpecificationToCriteria(SimpleJpaRepository.java:762) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
执行以下内容时可以看到该错误:
ExampleMatcher matcher = ExampleMatcher
.matchingAll()
.withStringMatcher(
ExampleMatcher.StringMatcher.REGEX
);
请注意,上面的代码编译得很好,执行时会发生错误。