2014-12-31 1 views
1

, 우리는 web.xml에

<context-param> 
    <param-name>spring.profiles.active</param-name> 
    <param-value>Production,Customer1</param-value> 
</context-param> 

2 개 활성 프로파일을 가지고 우리가 동적으로 일부 속성 파일을로드 할 아래로 : ${spring.profiles.active[1]}하지만 운 :

<util:properties id="accountPolicy" 
     location="classpath:/configs/${spring.profiles.active}/sample.properties" /> 

${spring.profiles.active} 두 개의 프로파일이 있기 때문에 될 수있다, 작동하지 않는, 내가 좋아하는 몇 가지 검색을 시도!

대한 의견

업데이트 :

내가 아래 시도 ${spring.profiles.active}는 쉼표로 분리 된 목록을 것 같다 :

<util:properties id="signConditions" 
     location="classpath:/configs/#{ {'${spring.profiles.active}'.split(',')}.get(1) }/sample.properties" /> 

그러나 오류는 XML parsser 오류가있을 것으로 보인다 :

org.springframework.expression.ParseException: 
Expression 'classpath:/configs/#{ {'Production,Customer1'.split('' @ 19: No ending suffix '}' for expression starting at character 19: #{ {'Production,Customer1'.split(' 
+0

은 사소한 것처럼 들릴 수도 있지만 단일 프로필로 시도 했습니까? –

+0

예, $ {spring.profiles.active}가 arrayList이고 splitted되어야한다고 생각합니다. –

+0

ok ..'# {spring.profiles.active [1]}'로 확인해야한다고 생각합니다 (' #'{'$ 대신에'#') –

답변

1

나는 더 적절한 방법은 뭔가를하는 것입니다 E : (당신이 무엇을하고 있는지로) 프로필이 내 댓글 대신 교체 속성과 같은 응용 프로그램의 맥락에서 구성 프로파일로 사용할 수


편집 기반을 해야하는

<beans profile="Production"> 
    <!-- some other stuff for Production profile --> 
</beans> 

<beans profile="Customer1"> 
    <util:properties id="accountPolicy" 
     location="classpath:/configs/Customer1/sample.properties" /> 
    <!-- some other stuff for Customer1 profile --> 
</bean> 

:

당신이 찾고있는 것은 (적어도 지금은 아닙니다) 스프링 프로파일 기능의 적절한 사용 사례가 아닙니다. 당신이하려고하는 것은 시스템 속성에 속성 자리 홀더 작업 기반을 갖는 것입니다. 그러나 프로필 활성화는 다른 방법으로 수행 할 수 있습니다. 즉, spring.profiles.active 시스템 속성이없는 프로필을 사용할 수 있습니다. 당신이하는 일은 믿을만하지 않습니다. 이 시스템 등록 정보를 전달하는 것이 좋은 경우

, 왜 그런 짓을하지 :

  1. 가지고 계정 정책 (및 기타 물건)을 포함 할 것이다 고객에게 배포 나타내는 Customer라는 프로필,
  2. 예를 들어, key = 'customerCode'및 value가 고객의 식별자 인 시스템 특성을 전달하십시오. 당신이 프로필의 적절한 사용을하고 -Dspring.profiles.active="Production,Customer" -DcustomerCode=Customer1

    번호 : 당신이해야 할 일을 그렇게함으로써

, 당신은 같이해야 보이는 응용 프로그램에 필요한

<beans profile="Production"> 
    <!-- some other stuff for Production profile --> 
</beans> 

<beans profile="Customer"> 
    <util:properties id="accountPolicy" 
     location="classpath:/configs/${customerCode}/sample.properties" /> 
    <!-- some other stuff for Customer1 profile --> 
</bean> 

및 시스템 특성입니다 각 고객에 대해 accountPolicy을 복제해야합니다.

+0

네, 문제는 모든 사용자가이 줄을 반복해야한다는 것입니다. '. xml 구문 분석과 관련된 오류를 검토 했습니까? –

+0

하지만 당신이하려고하는 것은 활성 프로필의 시스템 속성에 단순히 속성 자리 표시자를 설정하는 것입니다. 그러나 시스템 속성없이 프로필을 활성화하는 다른 방법이 있습니다. 당신이하려는 것은 단순히 미래의 함정에 빠지게하는 것입니다. 당신이하려고하는 것은 프로파일을위한 적절한 유스 케이스가 아니다. 적어도 Spring에 의해 제공되는 현재 프로파일 기능에는 적합하지 않다. –

+0

Customer 코드를위한 프로퍼티를 가지며, Customer Sample 프로퍼티 파일을 한 라인 만 가진다. 그렇다면 시스템 속성을 통해 고객 코드를 전달하는 것입니다. 시스템 속성은 현재 수행하려고 시도하는 것보다 어렵지 않습니다. –

관련 문제