spring 加载自定义配置

来源:互联网 发布:龙珠直播软件 编辑:程序博客网 时间:2024/05/17 15:18

package com.lawu.eshop.order.srv.constants;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.PropertySource;import org.springframework.stereotype.Component;@Configuration@ComponentScan@EnableAutoConfiguration@ConfigurationProperties(prefix = "order")@PropertySource(value = "classpath:job.properties", ignoreResourceNotFound = true)@Componentpublic class JobConstant {@Value("${order.refund.request.time}")private int refundRequestTime;private int automaticCancelOrder;public int getRefundRequestTime() {return refundRequestTime;}public void setRefundRequestTime(int refundRequestTime) {this.refundRequestTime = refundRequestTime;}public int getAutomaticCancelOrder() {return automaticCancelOrder;}public void setAutomaticCancelOrder(int automaticCancelOrder) {this.automaticCancelOrder = automaticCancelOrder;}}


配置类,自动装配


# order configorder.refund.request.time=7order.automaticCancelOrder=2

配置文件

原创粉丝点击