@PropertySource 学习笔记

本文介绍了Spring中的@PropertySource注解,用于加载指定属性文件。在大量配置属性时,@Value注解可能会变得繁琐。文章提到了@ConfigurationProperties注解作为替代方案,该注解能自动绑定配置文件中的属性到类的字段。同时,讨论了如何处理未找到的字段和验证失败的情况,如通过ignoreUnknownFields和ignoreInvalidFields参数进行配置。
摘要由CSDN通过智能技术生成

@PropertySource注解加载指定的属性文件

package com.myproject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.PropertySource;
@SpringBootApplication
@EnableEurekaServer
//File协议主要用于访问本地计算机中的文件,就如同在Windows资源管理器中打开文件一样。 
@PropertySource(value = "file:${user.dir}/Config/application.properties")
public class EurekaServerApplication {
	public static void main(String[] args) {
		SpringApplication.run(EurekaServerApplication.class, args);
	}
}
package org.springframework.context.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
imp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值