字段修改产生的异常
由于我们的项目的日志采集系统应用的是logback-spring 日志采集所以很多错误由于日志级别的更改打印出来的全都是一样的错误,在进行测试的时候由于实体类字段的修改,使得报了如下错误,一开始第一眼是bean注入的错误就开始找注解的错误,但是并没有发现注解使用错误,后来把错误往后拉取看见,`projectId` 才知道原来是实体属性修改了,所以产生了这个异常:
16:13:56.037 [main] INFO org.hibernate.Version - [logVersion,45] - HHH000412: Hibernate Core {5.2.17.Final}
16:13:56.039 [main] INFO org.hibernate.cfg.Environment - [<clinit>,213] - HHH000206: hibernate.properties not found
16:13:56.089 [main] INFO org.hibernate.annotations.common.Version - [<clinit>,66] - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
16:13:56.250 [main] INFO org.hibernate.dialect.Dialect - [<init>,157] - HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
16:13:57.093 [main] INFO org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - [log,87] - Initialized JPA EntityManagerFactory for persistence unit 'default'
16:13:57.932 [main] WARN o.s.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - [log,87] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'projectController': Unsatisfied dependency expressed through field 'projectServiceCN'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'projectServiceCNImpl': Unsatisfied dependency expressed through field 'projectDataRepositoryCN'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectDataRepositoryCN': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List cn.sciencedb.repository.ProjectDataRepositoryCN.findByProject(java.lang.String)! No property project found for type ProjectDataZhCN! Did you mean 'projectId'?
16:13:57.933 [main] INFO org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - [log,87] - Closing JPA EntityManagerFactory for persistence unit 'default'
16:13:57.941 [main] INFO com.alibaba.druid.pool.DruidDataSource - [close,1825] - {dataSource-1} closed
16:13:58.084 [AsyncReporter{org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender@53b3b8be}] INFO org.springframework.context.annotation.AnnotationConfigApplicationContext - [log,87] - Refreshing SpringClientFactory-10.0.86.196: startup date [Tue Oct 16 16:13:58 CST 2018]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7f7af971
16:13:58.155 [AsyncReporter{org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender@53b3b8be}] INFO o.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - [log,87] - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
16:13:58.247 [AsyncReporter{org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender@53b3b8be}] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext - [log,87] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ribbonClientConfiguration': Unsatisfied dependency expressed through field 'propertiesFactory'; nested exception is org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'propertiesFactory': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
16:13:58.250 [main] INFO org.apache.catalina.core.StandardService - [log,180] - Stopping service [Tomcat]
解决办法:把 spring data jpa 中的 repository(dao层)中的自定义方法findByProject(project) 修改为 findByProjectId(projectId) 就好了。