spring 의 properties 분석

2460 단어 properties
일반적으로 Property Place holder Configurer 를 사용 하여 대체 자 를 대체 합 니 다.예 를 들 어:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

  <property name="locations">

      <value>classpath:com/foo/strategy.properties</value>

  </property>

  <property name="properties">

      <value>custom.strategy.class=com.foo.DefaultStrategy</value>

  </property>

</bean>

spring 2.5 이후 사용 가능
<context:property-placeholder location="classpath:com/foo/jdbc.properties"/>

그 본질은 Property Placeholder Configure(3.1 이전)또는 Property Sources Placeholder Configure(3.1 이후)를 등록 한 것 이다.
Tip:
Property Placeholder Configure 에 내 장 된 기능 이 매우 풍부 합 니 다.${xxx}에서 정 의 된 xxx 키 를 찾 지 못 하면 JVM 시스템 속성(System.getProperty()과 환경 변수(System.getenv()에서 찾 을 수 있 습 니 다.시스템 PropertiesMode 와 searchSystem Environment 속성 을 사용 하면 개발 자가 이 행동 을 제어 할 수 있 습 니 다.
그리고 Property Sources Placeholder Configurer 는 이 를 바탕 으로 Environment and Property Source 와 더욱 잘 어 울 릴 것 입 니 다.
그리고 다음 과 같은 몇 가 지 를 주의해 야 한다.
1.Property Placeholder Bean Definition Parser 의 부모 클래스 에서 shouldGenerate Id 는 true 로 돌아 갑 니 다.즉,기본적으로 모든 bean 에 유일한 이름 을 만 듭 니 다.     이 때 order='1'을 먼저 스 캔 합 니 다.order='2'를 스 캔 하지 않 은 4,기본 적 인 상황 에서 ignore-unresolvable;찾 지 못 한 경우 이상 을 던 지 는 지 여부 다.기본 false:이상 던 지기;

좋은 웹페이지 즐겨찾기