FrameWork_ETC/Spring

스프링 어노테이션과 xml설정으로 properties 불럳오기

아라한사 2014. 8. 1. 15:00

bean xml 설정


<util:properties id="msgProperties" location="classpath:sample/di/message/message.properties" />

<bean id="message" class="sample.di.message.MessageServiceImpl">

<property name="message" value="#{msgProperties.message}" />

</bean>


public class MessageServiceImpl implements MessageService {

private String message;


public String getMessage() {

return message;

}


public void setMessage(String message) {

this.message = message;

}


}



어노테이션 설정

<util:properties id="msgProperties" location="classpath:sample/di/message/message.properties" />

<context:annotation-config />

<context:component-scan base-package="*"/>


@Component

public class MessageServiceImpleAnnotation {


@Value("#{msgProperties.message}")

private String message;

public String getMessage(){

return message;

}

}