六、springboot中通过properties配置文件给类属性赋值

通过properties配置文件给类属性赋值呢?

举例:

1、首先我在src/main/resources文件夹下新建个company.properties文件,设置一些数据

ge.companyName=\u6210\u90FD\u683C\u667A\u7F51\u7EDC\u79D1\u6280\u6709\u9650\u516C\u53F8
ge.telphone=028-88594556
ge.lawPerson=\u4F55\u61A8\u950B

 

2、新建一个类,叫做CompanyBean

@ConfigurationProperties(prefix="ge") 注解给属性添加前缀,因为在properties文件中属性前面有前缀ge,后面的属性名要和类中的属性名一致对应
@PropertySource(value= {"classpath:company.properties"})  引入配置文件

package com.ge.springboot.bean;

import java.io.Serializable;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Component
@Configur
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值