Web/Spring 2018. 8. 12. 13:46

@Value 어노테이션(SpEL 이용)


@Component

public class Sample{

@Value("Some currency")

private String currency;

}



@Component

public class Sample{

@Value("#{configuration.environment}")

private String environment;

@Value("#{configuration.getCountry()}")

private String country;


@Autowired

public void printCountry(@Value("#{configuration.getCountry()}" String country)}

System.out.println(count);   =>메소드 및 생성자 인자에 @Value를 사용할때는 반드시 @Autowired, @Resource 등의 어노테이션이 존재해야한다.

}

}


@Component("configuration")

public class config{

public static String environment="DEV";


public String getCountry(){

return "Some Country";

}

}


위와 같이 @Value와 SpEL을 이용 할 수 있다. 그리고 SpEL 같은 경우는 xml 설정에서도 이용 할 수 있다.


<bean id="sample" class=".....Sample">

<property name="environment" value="#{configuration.environment}" />

<property name="country" value="#{configuration.getCountry()}" />

.....

</bean>

posted by 여성게
: