728x90
반응형
728x90
반응형

스프링 프레임워크를 사용하면서 root-context.xml와 servlet-context.xml 차이에 대한 궁금증에 생겨 포스팅합니다.

root-context.xml와 servlet-context.xml는 두 파일 모두 객체(bean)를 정의한다는 공통점이 있습니다.


root-context.xml 는 

 -jsp와 관련이 없는 객체(bean)를 설정해줍니다. 아래 그림과 같이(service, repository)

 -비즈니스 로직을 위한 설정입니다.


servlet-context.xml 는 

 -jsp와 관련 있는 객체(bean)를 설정해줍니다. (controller, MultipartResolver(파일 업로드), Interceptor(로그인) 등),  

 -URI와 관련 설정을 담는 클래스는 servlet-context.xml에 들어가야 합니다.

 -WEB Application에서 Client의 요청을 받기 위한 설정입니다.




https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc


root-context.xml


	
		
	
	
	
	<context:component-scan base-package="org.zerock.persistence"/>
	
	
	<context:component-scan base-package="org.zerock.service"/>
	
	>
	<context:component-scan base-package="org.zerock.aop"/>
	<aop:config/>
	
	
	<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
	
	
	
			
	<tx:annotation-driven/> 
  

servlet-context.xml

  
  <context:component-scan base-package="org.zerock.controller" />
	
	<!-- 17.11.1 파일 저장 경로 설정 -->
	<beans:bean id="uploadPath" class="java.lang.String">
		<beans:constructor-arg value="C:\\springUploadTest\\upload"/>
	</beans:bean>
	
	<beans:bean id="multipartResolver" 
	class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		 
	</beans:bean>
	
	
	
	
	
	
	
	
		
			<mapping path="/user/loginPost" />
			<beans:ref bean="loginInterceptor" />
		
		
		
			<mapping path="/sboard/register "/>
			<mapping path="/sboard/modifyPage" />
			<mapping path="/sboard/removePage" />
			<beans:ref bean="authInterceptor"/>
    
		
	
 

  


728x90
반응형
728x90
반응형


런타임 오류 내용입니다.

 
org.springframework.validation.BeanPropertyBindingResult: 2 errors Field error in object 'cri' on field 'page': rejected 
value []; codes [typeMismatch.cri.page,typeMismatch.page,typeMismatch.int,typeMismatch]; arguments 
[org.springframework.context.support.DefaultMessageSourceResolvable: codes [cri.page,page]; arguments []; default 
message [page]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for 
property 'page'; nested exception is java.lang.NumberFormatException: For input string: ""] Field error in object 'cri' on 
field 'perPageNum': rejected value []; codes
[typeMismatch.cri.perPageNum,typeMismatch.perPageNum,typeMismatch.int,typeMismatch]; arguments 
[org.springframework.context.support.DefaultMessageSourceResolvable: codes [cri.perPageNum,perPageNum]; 
arguments []; default message [perPageNum]]; default message [Failed to convert property value of type 
'java.lang.String' to required type 'int' for property 'perPageNum'; nested exception is 
java.lang.NumberFormatException: For input string: ""]

 


게시판 수정 중 컨트롤러에서 value=""빈칸으로 발생하여 sumbit시에 값을 읽지 못해 발생한 오류입니다.

컨트롤러에서 @ModelAttribute를 명시해주지 않아서 생긴 오류였습니다.

@RequestParam이나 @MddelAttribute 어노테이션을 사용하면 메소드의 길이가 길어지고 복잡하다고 느낄 수 있습니다.

하지만 이를 생략하는 것은 저처럼 오류를 범할 수 있으니 꼭 명시해주는게 좋습니다.


728x90
반응형
728x90
반응형

+ Recent posts