在 CatDao中添加自定义查询方法后,启动报错

  1 2019-06-11 11:06:13.874  INFO 14700 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.7.Final}
2 2019-06-11 11:06:13.890 INFO 14700 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
3 2019-06-11 11:06:16.270 INFO 14700 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
4 2019-06-11 11:06:17.403 INFO 14700 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
5 2019-06-11 11:06:23.144 INFO 14700 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
6 2019-06-11 11:06:23.318 INFO 14700 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
7 2019-06-11 11:06:25.815 WARN 14700 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
8 2019-06-11 11:06:25.816 INFO 14700 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
9 2019-06-11 11:06:25.842 INFO 14700 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
10 2019-06-11 11:06:25.855 INFO 14700 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
11 2019-06-11 11:06:25.858 INFO 14700 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
12 2019-06-11 11:06:26.021 INFO 14700 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
13
14 Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
15 2019-06-11 11:06:26.228 ERROR 14700 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
16
17 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
18 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:324) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
19 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1395) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
20 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
21 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
22 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
23 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
24 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
25 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
26 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
27 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
28 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
29 at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
30 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
31 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
32 at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
33 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
34 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
35 at com.SpringBootHelloApplication.main(SpringBootHelloApplication.java:16) [classes/:na]
36 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
37 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
38 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
39 at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
40 at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.3.RELEASE.jar:2.1.3.RELEASE]
41 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
42 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:324) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
43 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1395) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
44 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
45 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
46 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
47 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
48 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
49 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
50 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeanByName(AbstractAutowireCapableBeanFactory.java:452) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
51 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:526) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
52 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
53 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:636) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
54 at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
55 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
56 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
57 ... 22 common frames omitted
58 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
59 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
60 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
61 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
62 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
63 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
64 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
65 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
66 at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
67 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1247) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
68 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
69 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:520) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
70 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
71 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:636) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
72 at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
73 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
74 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
75 ... 36 common frames omitted
76 Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
77 at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:82) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
78 at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
79 at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:208) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
80 at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
81 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:566) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
82 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
83 at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_121]
84 at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_121]
85 at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1049) ~[na:1.8.0_121]
86 at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_121]
87 at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_121]
88 at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_121]
89 at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_121]
90 at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_121]
91 at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_121]
92 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:561) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
93 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:551) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
94 at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_121]
95 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:551) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
96 at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
97 at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
98 at org.springframework.data.util.Lazy.getNullable(Lazy.java:211) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
99 at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
100 at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
101 at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:119) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
102 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
103 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
104 ... 51 common frames omitted
105 Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
106 at org.hibernate.metamodel.internal.AbstractManagedType.checkNotNull(AbstractManagedType.java:128) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
107 at org.hibernate.metamodel.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:113) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
108 at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:593) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
109 at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:577) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
110 at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.getTypedPath(JpaQueryCreator.java:379) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
111 at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:302) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
112 at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:207) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
113 at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:120) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
114 at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:57) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
115 at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:119) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
116 at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
117 at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
118 at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:145) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
119 at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$CountQueryPreparer.<init>(PartTreeJpaQuery.java:268) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
120 at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:77) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
121 ... 77 common frames omitted
122
123
124 Process finished with exit code 0

1.controller层

@RestController
@RequestMapping("/cat")
public class CatController {
@Resource
private CatService catService;
@GetMapping(value = "/findByCatName")
public List<Cat> findByCatName(String catName){
return catService.findByCatName(catName);
}
}

2.service层

@Service
public class CatService {
@Resource
private CatDao catRepository; public List<Cat> findByCatName(String catName){
return catRepository.findByCatName(catName);
}
}

3.dao层

public interface CatDao extends JpaRepository<Cat,Integer> {
//根据名称查询
List<Cat> findByCatName(String catName);
}

这样看着代码是没什么问题,而且之前在启动项目的时候,我可以通过代码生成数据库表了,所以就很自然的认为,实体是没有问题的;

但是在网上查了很多资料都是说dao层的字段名称和实体的不一致的问题,所以我就把注意力放在dao层上面去查问题,就这样查了好久,依然觉得代码没问题(很无奈啊....)

后来实在没有办法了就又去检查实体字段名称的定义,终于找到问题了,是因为字段的定义不符合规范,虽然之前已经可以通过实体生成表结构,但是在使用查询的时候,不知道为

什么还是注入不了(这个目前还没有搞清楚),最后把正确的实体贴出来,以来警醒自己吧

之前定义的变量名称是:CatAge/CatName

@Entity
public class Cat {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private int id ;//主键 private String catName;//姓名 private int catAge; //年龄 public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getCatName() {
return catName;
} public void setCatName(String catName) {
this.catName = catName;
} public int getCatAge() {
return catAge;
} public void setCatAge(int catAge) {
this.catAge = catAge;
}
}

总结:

这次的错误主要是在创建实体的时候,变量的命名不规范造成的,所以简单总结下java的常用的几个命名规则:

1.包:所有包的命名必须采用小写英文字母;

2.类:采用驼峰命名法,类名的首字母必须采用大写的形式,如果类名为多个单词组合的话,那么每个字母的首字母必须采用大写,eg:CatDao.java;

3. 方法:采用驼峰命名法,首字母以小写开头,每个单词首字母大写(第一个单词除外);

4.变量:首字母以小写开头,每个单词首字母大写(第一个单词除外);

Springboot 之JPA查询报错的更多相关文章

  1. Jpa自定义查询报错(Failed to convert from type [java.lang.Object[]] to type)

    Jpa自定义查询报错 问题背景 今天遇到一个奇怪的报错"Failed to convert from type [java.lang.Object[]] to type",这个报错 ...

  2. sqli注入--利用information_schema配合双查询报错注入

    目录 sqli-labs 5.6双查询报错注入通关 0x01 获取目标库名 0x02 获取库中表的数量 0x03 获取库中表名 0x04 获取目标表中的列数 0x05 获取目标表的列名 0x06 从列 ...

  3. sql注入--双查询报错注入原理探索

    目录 双查询报错注入原理探索 part 1 场景复现 part 2 形成原因 part 3 报错原理 part 4 探索小结 双查询报错注入原理探索 上一篇讲了双查询报错查询注入,后又参考了一些博客, ...

  4. sql注入--双查询报错注入

    sql注入--双查询报错注入 背景:在sqli-labs第五关时,即使sql语句构造成功页面也没有回显出我们需要的信息,看到了有使用双查询操作造成报错的方式获得数据库信息,于是研究了一下双查询的报错原 ...

  5. 新建SpringBoot项目运行页面报错Whitelabel Error Page This application has no explicit mapping for /error, so yo

    新建SpringBoot项目运行页面报错Whitelabel Error Page This application has no explicit mapping for /error, so yo ...

  6. springboot 启动的时候报错 Error creating bean with name 'solrClient'

    springboot 启动的时候报错: org.springframework.beans.factory.BeanCreationException: Error creating bean wit ...

  7. MySQL查询报错 ERROR: No query specified

    今天1网友,查询报错ERROR: No query specified,随后它发来截图. root case:查询语法错误 \G后面不能再加分号;,由于\G在功能上等同于;,假设加了分号,那么就是;; ...

  8. 【mybatis】【mysql】mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

    mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains no ...

  9. 【Elasticsearch】ES中时间查询报错:Caused by: ElasticsearchParseException[failed to parse date field [Sun Dec 31 16:00:00 UTC 2017] with format [yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis]];

    ES中时间查询报错:Caused by: ElasticsearchParseException[failed to parse date field [Sun Dec 31 16:00:00 UTC ...

  10. 关于springboot 连接mysql 数据库报错问题

    springboot连接MySQL运行报错: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more ...

随机推荐

  1. 「六」Goaccess实现可视化

    下载 apt install goaccess 使用goaccess进行监控 LANG="en_US.UTF-8" bash -c 'goaccess logs/access.lo ...

  2. AI与.NET技术实操系列(二):开始使用ML.NET

    引言 在当今技术飞速发展的时代,机器学习(Machine Learning, ML)已成为推动创新和变革的核心力量.从智能推荐系统到自动化决策工具,ML的应用无处不在,深刻影响着我们的生活和工作方式. ...

  3. win7系统清理C盘空间方法实测

    问题描述:win7电脑C盘容易满,采用如下方法清理 方法一:win+r,输入%temp%查看临时文件,手动删除不需要的文件 方法二:减小休眠文件:如果你很少使用休眠模式,可以通过win+r输入cmd命 ...

  4. Oracle 23ai TPC-H 执行情况

    TPC-H是一个广泛使用的基准测试,用于评估数据库系统在决策支持系统(DSS)场景下的性能. 在昨天的文章中,我们完成了<Oracle 23ai TPC-H 测试环境部署>,本文将继续记录 ...

  5. 自动化-Yaml文件写入函数封装

    1.文件布局 打开文件修改读取方式为w dump函数写入文件 写入中文 使用allow_unicode=True class ReadConfiYaml: def __init__(self,yaml ...

  6. mysql - 视图的操作 创建,修改,删除,查看

    只保存sql逻辑,不保存查询结果 视图可以看作是封装了多条sql语句,之后使用的时候就像普通表一样,而这个表上的字段则是创建视图时,select 后边跟的字段,支持列的别名. 创建 语法: creat ...

  7. Keil中设置显示空白符,并将Tab键使用4个空格代替

    前言 Keil 的默认设置是没有将 Tab 键使用空格代替的,不同的文本编辑器对 Tab 键所占的空格数不同,有占 2 个空格的,也有占 4 个空格的,这就导致同样的代码在不同的编辑器中缩进不同,虽不 ...

  8. linux 根目录扩容方法

    准备知识 linux volume 1.(PV)physical volume disk : 物理硬盘 物理硬盘需要转换成lvm(logic volume manage)可识别的状态,将磁盘的syst ...

  9. static修饰成员变量的特点及static修饰成员变量内存图解-java se进阶 day01

    1.static介绍 static是静态的意思,它可以用于修饰成员变量和成员方法 2.static的特点 1.被static修饰了的成员变量,可以被类中的所有对象所共享 虽然stu02没有给schoo ...

  10. dotnet 命令启动报错

    Windows 7 或 Windows Server 2008 R2 上安装 .NET Core SDK 2.x 后 dotnet 命令启动报错 可以通过下载以下系统补丁解决 感谢下载 Windows ...