2012-03-13 3 views
1

4 개의 정수 args가있는 생성자가있는 클래스가 있습니다. 그것은과 같이 스프링 XML로 구성되어c-namespace 및 유형 변환

maxConnectionsPerHost=50 
maxTotalConnections=50 
connectionTimeout=500 
soTimeout=100 

그러나 나는 다음과 같은 오류 얻을 :

<bean id="mySearchService" class="app.service.MySearchService" 
    c:maxConnectionsPerHost="${maxConnectionsPerHost}" 
    c:maxTotalConnections="${maxTotalConnections}" 
    c:connectionTimeout="${connectionTimeout}" 
    c:soTimeout="${soTimeout}" /> 

내 속성 파일이있다 나는 그래서 <constructor-arg value="..." />를 사용하는 경우

Error creating bean with name 'mySearchService' defined in class path resource [applicationContext.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [java.lang.Integer]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?

이 작동을 c-namespace가 constructor-arg와 같은 방식으로 변환을 입력하지 않는지 궁금합니다. 문서는 결코 당신이 실제로 쓸 필요가 있도록 명시 적으로 — 말할 것 없지만, 내가 — 추론이에서

The c: namespace uses the same conventions as the p: one (trailing -ref for bean references) for setting the constructor arguments by their names.

:

The p-namespace is not as flexible as the standard XML format. For example, the format for declaring property references clashes with properties that end in Ref , whereas the standard XML format does not.

그 :

답변

0

The documentation는 것을 언급

<bean id="mySearchService" class="app.service.MySearchService" 
    c:max-connections-per-host="${maxConnectionsPerHost}" 
    c:max-total-connections="${maxTotalConnections}" 
    c:connection-timeout="${connectionTimeout}" 
    c:so-timeout="${soTimeout}" /> 

us camel-case가 아닌 하이픈으로 연결된 속성 - 이름.

+0

값이 bean 참조 값이면 p 네임 스페이스는 -ref와 함께 camel case 이름을 사용합니다. 그래서 나는 이름에서 대시가 의미가 있다고 생각하지 않는다. 내가 사용한 낙타의 경우 이름은 구조물이나 이름과 정확히 일치합니다. – Kevin

+0

@ Kevin : 그렇다면 어떻게'-ref'가'Ref'로 끝나는 속성들과 충돌 할 수 있습니까 (제가 인용 한 첫 번째 스 니펫에서 언급했듯이)? 제가 말하고자하는 것은, 생성자 인수가 예를 들어,. 'maxConnectionsPerHost', 그러면 속성 이름이 필요하다고 생각합니다. 'c : 호스트 별 max-connections '. (이상하게 보입니다. 그렇지만 그렇지 않다면 문서의 문장이 실제로 의미가 없습니다.) – ruakh

+0

p-namespace를 영원히 사용하고 있다는 것을 제외하고는 어떻게 대답 할 수 있을지 모르겠습니다. 그리고 값은 추가 접미사 "-ref"로 참조와 구별된다는 점을 제외하고는 이름이 세터 이름과 정확히 일치해야합니다 (예 : 낙타의 경우). – Kevin