前言

记录一下,这个异常的处理,以下控制台输出的日志

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-08 22:18:31.124 ERROR 2684 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'messageService': Unsatisfied dependency expressed through field 'messageRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: This class [class com.xxx.Message] does not define an IdClass
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at com.xx.MainApplication.main(MainApplication.java:11) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: This class [class com.xxx.Message] does not define an IdClass
	... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: This class [class com.xxx.Message] does not define an IdClass
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
	... 29 common frames omitted


Process finished with exit code 1

可以看到日志中关键的一条信息为

Caused by: java.lang.IllegalArgumentException: This class [class com.xxx.Message] does not define an IdClass

可是网上搜出来的都是关于jpa IdClass 注解之类的信息,或者说根本不是我遇到的问题,当然也就无法通过他们的方案解决; 后来在同事的火眼金睛的帮助下,发现了问题所在,原因实在不好意思说出来

不好意思

原来我在定义数据表的时候,一个复制粘贴多了个@Id注解,导致建表时DDL语句就出错了,而在日志中我疏忽了这个问题,特此记录一下,以免以后再犯这种低级错误;

贴一下,这个羞羞的错误,把多出的@Id去掉就好了

@Entity
@Table(name = "message_table")
public class Message implements Serializable {

    private static final long serialVersionUID = -2924506101675558135L;
    @Id
    @GeneratedValue
    private Long id;

//就是这里多了个Id注解
    @Id
    @Column(nullable = false)
    private String content;
.......
}