一、描述错误

当我在读取自定义配置文件信息时,希望返回到前台(以json的格式),但是报错。

错误信息大致如下(未完全粘贴):

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver

 

二、大致情况

就是后台返回的数据不能正确被序列化

 

三、看代码

resource.properties

######################################
##########   存储配置相关的信息         ########## 
######################################
com.xf.name=陈独秀
com.xf.age=21
com.xf.gender=男
com.xf.school=家里蹲大学
com.xf.address=里根

映射实体类:

package com.xf.database.entity;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/*
 * 读取自定义配置文件信息
 * 当在自定义配置文件存储中文时,读取文件信息的
 * @PropertySource(value="classpath:config/resource.properties",
encoding="UTF-8")
 *  需要指定编码encoding="UTF-8" 才不会显示乱码
 * 
 */
@Configuration
@ConfigurationProperties(prefix="com.xf") //指定前缀
@PropertySource(value="classpath:config/resource.properties",
encoding="UTF-8")
public class CResource{
    /**
     * 
     */
    private String name; // 姓名
    private Integer age; // 年龄
    private String school; // 学校
    private String address; // 地址
    private String gender; // 性别
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public String getSchool() {
        return school;
    }
    public void setSchool(String school) {
        this.school = school;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    @Override
    public String toString() {
        return "Resource [name=" + name + ", age=" + age + ", school=" + school + ", address=" + address + ", gender="
                + gender + "]";
    }
    
}
实体类

相关文章: