IT/SpringBoot

@Value 어노테이션

WsCode 2022. 1. 18. 21:06

@Value어노테이션은 스프링빈에 등록된 객체에 기본값을 부여할수있다.

@Component
public class Car{
	@Value("10")
	public int speed;
}

위처럼 Car Class @Value에 10으로 주면 기본값이 10으로 출력된다.

@Component
public class Car{
	@Value("${test.value}")
	public int speed;
}
application.properties
test.value=100

@Value에 ${properties값}으로 설정하여 사용도가능하다.