spring boot 的報錯

  1. dao 字段名字沒映射好

...

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-09-03 19:39:23.978 ERROR 28777 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.gdp.demo3.entity.User com.gdp.demo3.dao.UserDao.findByUsername(java.lang.String)!

...

大概這樣一段報錯,實際是我數據庫和實體類字段沒對應上。

package com.xxx.xxx.entity

import java.util.*
import javax.persistence.*
import javax.validation.constraints.NotEmpty
import javax.validation.constraints.Size

@Table(name = "user")
@Entity
class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long = -1

    @Column(unique = true)
    @NotEmpty(message = "用戶名不能爲空")
    @Size(message = "用戶名長度在1~20之間", max = 100, min = 1)
    var userName: String = ""

    @NotEmpty(message = "密碼不能爲空")
    @Size(message = "密碼長度在6~100之間", max = 100, min = 6)
    var password: String = ""
}

數據庫中 userName 是全部小寫,沒有任何分割符的,改成 username 就好了。

2.Freemarker 頁面老是 404

Spring Boot 2.3.3 的時候發現的,Freemarker 的默認後綴發生了變化,以前可能是 .ftl,現在是 .ftlh。可能是這個造成不能找的模板的。

application.properties 文件設置 spring.freemarker.suffix=.ftlh 可以自己隨意設置後綴。

spring boot 的報錯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章