java.lang包含_原因:java.lang.IllegalArgumentException:包含(1)...
我正在開發(fā)Spring Boot Redis示例.在此示例中,我開發(fā)了一些自定義方法,這些方法基于RoleName提取詳細(xì)信息.對于以下方法userRepository.findByRole_RoleName(“ ADMIN”)或userRepository.findByMiddleNameContaining(“ Li”);,我們得到以下異常.
任何人都可以請?zhí)峁┏绦虻闹羔槅?#xff1f;所有其他方法都可以正常工作.但是只是這種方法引起了問題.我將在下面發(fā)布所有必需的代碼以供參考.
錯(cuò)誤:
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
at com.baeldung.MainAppDemo.main(MainAppDemo.java:21)
Caused by: java.lang.IllegalArgumentException: CONTAINING (1): [IsContaining, Containing, Contains]is not supported for redis query derivation
at org.springframework.data.redis.repository.query.RedisQueryCreator.from(RedisQueryCreator.java:67)
at org.springframework.data.redis.repository.query.RedisQueryCreator.create(RedisQueryCreator.java:53)
at org.springframework.data.redis.repository.query.RedisQueryCreator.create(RedisQueryCreator.java:41)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:119)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81)
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.createQuery(KeyValuePartTreeQuery.java:211)
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.prepareQuery(KeyValuePartTreeQuery.java:148)
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:106)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:602)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy65.findByMiddleNameContains(Unknown Source)
at com.baeldung.MainAppDemo.run(MainAppDemo.java:38)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:792)
... 5 common frames omitted
2018-11-04 00:27:29,639 INFO [main] org.springframework.context.support.AbstractApplicationContext: Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6f96c77: startup date [Sun Nov 04 00:27:26 IST 2018]; root of context hierarchy
2018-11-04 00:27:29,645 INFO [main] org.springframework.jmx.export.MBeanExporter: Unregistering JMX-exposed beans on shutdown
User.java
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("user")
public class User {
private @Id String id;
private @Indexed String firstName;
private @Indexed String middleName;
private @Indexed String lastName;
private Role role;
}
Role.java
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("Role")
public class Role {
private @Id String id;
private @Indexed String roleName;
}
UserRepository.java
public interface UserRepository extends CrudRepository{
List findByFirstNameAndLastName(String firstName, String lastName);
List findByMiddleNameContains(String firstName);
List findByRole_RoleName(String roleName);
}
MainAppDemo.java
@SpringBootApplication
public class MainAppDemo implements CommandLineRunner{
@Autowired
private UserRepository userRepository;
public static void main(String[] args) {
SpringApplication.run(MainAppDemo.class, args);
}
@Override
public void run(String... args) throws Exception {
Role role1 = Role.builder().id("R1").roleName("ADMIN").build();
User user1 = User.builder().firstName("Matt").middleName("Mike").lastName("Wixson").role(role1).build();
Role role2 = Role.builder().id("R2").roleName("API").build();
User user2 = User.builder().firstName("John").middleName("Lima").lastName("Kerr").role(role2).build();
userRepository.save(user1);
userRepository.save(user2);
List u = userRepository.findByFirstNameAndLastName("Matt", "Wixson");
System.out.println("Find By First Name and Last Name = "+u.toString());
List u2 = userRepository.findByMiddleNameContains("Li");
System.out.println("Contains ="+u2);
List adminUser = userRepository.findByRole_RoleName("ADMIN");
System.out.println("ADMIN USER ="+adminUser);
}
}
更新:
我開發(fā)了這樣的查詢并從main方法調(diào)用,但仍然遇到相同的錯(cuò)誤.請?zhí)岢隹尚械慕鉀Q方案.
@Query("SELECT u FROM User u WHERE u.middleName LIKE :middleName ")
List findByMiddleNameContaining(@Param("middleName") String middleName);
總結(jié)
以上是生活随笔為你收集整理的java.lang包含_原因:java.lang.IllegalArgumentException:包含(1)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mat opencv java_Open
- 下一篇: jsp mysql 分页插件_知识分享: