web.xml에 있는 context param 접근에 대해서 질문이 있습니다.

442 views
Skip to first unread message

정대현

unread,
Sep 29, 2014, 10:54:22 PM9/29/14
to ks...@googlegroups.com
안녕하세요.

web.xml에 

<context-param>
<description>Group ID</description> 
<param-name>grpid</param-name>
<param-value>1</param-value>
</context-param>

이런식으로 기입 후 Controller에서 해당 값을 가져 올려구 하고 있습니다.
찾아 보니 

이렇게 ServletContextAware 이용해서 처리 하는데 sping 설계 사상에 맞는 건지 알고 싶습니다.

감사합니다.

Jisung, Ahn

unread,
Sep 29, 2014, 11:42:53 PM9/29/14
to ks...@googlegroups.com
스프링에서는 대부분의 설정값을 Property 로 대체하고 있습니다. 

이를 위해 다양한 PropertyConfigurer를 제공하는데요
ServletContext를 위해서 ServletContextPropertyPlaceholderConfigurer 를 제공하고 있습니다. 


를 참고해 보세요 


2014. 9. 30., 오전 11:54, 정대현 <ys2...@gmail.com> 작성:

--
이 메일은 Google 그룹스 'Korea Spring User Group Q&A' 그룹에 가입한 분들에게 전송되는 메시지입니다.
이 그룹에서 탈퇴하고 더 이상 이메일을 받지 않으려면 ksug+uns...@googlegroups.com에 이메일을 보내세요.
http://groups.google.com/group/ksug에서 이 그룹을 방문하세요.
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/ksug/e5e0f2be-6c37-44e5-b052-3b2ea6566c41%40googlegroups.com을(를) 방문하세요.
더 많은 옵션을 보려면 https://groups.google.com/d/optout을(를) 방문하세요.

Sanghyuk Jung

unread,
Sep 30, 2014, 3:45:57 AM9/30/14
to ks...@googlegroups.com
Spring 3.1부터는 <context:property-placeholder../>에 의해 등록되는  PropertySourcesPlaceholderConfigurer 에서 OS환경변수, system속성 등 모든 환경변수를 통합 참조할수 있습니다. 알려주신 stackoverflow 링크의 다음답변에도 그게 나와있네요.

ServletContextPropertyPlaceholer는 Deprecated 되었다고 나옵니다.

저도 한번 테스트를 해보니 web.xml에 알려주신대로 등록하고

servlet선언에서 참조하는 applicationContext설정파일에  같은곳에 아래와 같이 설정한후

    <context:property-placeholder local-override="true"/>

Controller에서 @Value 로 불러오니  web.xml에 넣은값이 잘 나오보니다..

    @Value("${grpid}")
    private String groupId;

2014년 9월 30일 오후 12:42, Jisung, Ahn <nar...@gmail.com>님이 작성:
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/ksug/C0992B27-5E9D-43A0-9FD0-7380C9DFE0A2%40gmail.com을(를) 방문하세요.

Sanghyuk Jung

unread,
Sep 30, 2014, 3:48:35 AM9/30/14
to ks...@googlegroups.com
toby님의 블로그의 아래 글에 관련 내용이 잘 설명되어 있었는데, 지금은 링크가 죽어있네요.. 아쉽습니다..

스프링 3.1 (7) 프로퍼티 소스 추상화와 PropertySourcePlaceholderConfigurer  :      http://toby.epril.com/?p=1191


2014년 9월 30일 오후 4:45, Sanghyuk Jung <ben...@gmail.com>님이 작성:
Reply all
Reply to author
Forward
0 new messages