본문 바로가기

Spring

"Spring servlet-context.xml과 root-context.xml의 차이점은?"

Spring servlet-context.xml vs root-context.xml


DTD 업그레이드 ⇒ xsd 


위의 사진은 servlet-context.xml 

아래는 root-context.xml이다 


즉, xsd가 여러 개 또는 한 개라는 차이가 prefix의 사용여부를 결정 짓는다


servlet-context.xml은 구분을 위해 prefix를 사용한다

<beans:beans ......

root-context.xml은 

<beans ...


※ prefix

xmlns(xml namespace) 여러개가 들어가 있다는 의미 (충돌회피를 위해 이름을 통해 구별한다!!)

xmlns:mvc ="http://www.springframework.org/schema/mvc"

mvc prefix로 받겠다


xmlns="http://www.springframework.org/schema/mvc"

xmlns:beans="http://www.springframework.org/schema/beans"    

xmlns:context="http://www.springframework.org/schema/context"


servlet-context.xml에는 세 개의 xsd가 있는데 모두 prefix 해줄 필요 없다. 하나만 prefix 안 해 줄 수 있는데 prefix 없이 바로 컨트롤+스페이스 해주면 사용할 수 있다.


<beans:beans ...> 태그에 beans prefix를 안 쓰고 싶다면 mvc에 prefix 주고 beans에는 생략해주면


xmlns:mvc="http://www.springframework.org/schema/mvc"             

xmlns="http://www.springframework.org/schema/beans"    

xmlns:context="http://www.springframework.org/schema/context"


=> <beans> 로 바꾸어 줄 수 있다.