2013-08-30 5 views
0

특성 파일을 사용하여 사용자 정의 유효성 검증 오류 메시지를 사용하려고합니다. 웹 컨텐츠/web-inf/폴더에 messages.properties 파일을 넣었습니다.스프링 mvc가 messages.properties 파일을 읽을 수 없습니다.

 <context:component-scan base-package="com.coaching.controller" /> 

<!-- Enable annotation driven controllers, validation etc... --> 
<mvc:annotation-driven /> 

<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views 
    directory --> 
<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 



    <property name="prefix"> 
     <value>/WEB-INF/views/</value> 
    </property> 
    <property name="suffix"> 
     <value>.jsp</value> 
    </property> 
</bean> 
<mvc:default-servlet-handler /> 
<mvc:resources mapping="/resources/**" location="/resources/" /> 

<bean id="messageSource" 
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 

    <property name="basename" value="/WEB-INF/messages" /> 

</bean> 

그리고 내 컨트롤러는 다음과 같습니다 :

NonEmpty.batchDomain.batchName=Invalid message 2. 

내 ApplicationContext를 파일입니다

@RequestMapping(method = RequestMethod.POST) 
public ModelAndView addBatch(
     @Valid @ModelAttribute("batchDomain") BatchDomain batchDomain, 
     BindingResult result, HttpServletRequest request, 
     HttpServletResponse response) throws Exception { 

    try { 

     if (result.hasErrors()) { 
      ModelAndView modelAndView = new ModelAndView("newBatch"); 
      return modelAndView; 
     } 
    } 

BatchDomain은 다음과 같습니다

 public class BatchDomain { 

@NotNull 
@NotEmpty 
@Size(min = 1, max = 100) 
private String batchName; 

@Min(1) 
@Max(1000) 
private int strength; 

} 

는 지금까지 내가 구글에서 보았 듯이, 나는 올바른 기준을 따른다. ach. 그렇다면이 문제의 원인은 무엇일까요?

+0

'WEB-INF' 대신 클래스 패스의 루트에 속성 파일을 넣으려고 할 수 있습니까? 봄 문맥에서 선언을 변경하십시오. –

+0

나는 http://stackoverflow.com/questions/11302531/how-to-place-a-file-on-classpath-in-eclipse에 따라 src 폴더에 파일을 놓았으며 컨텍스트 파일을 하지만 아무 일도 없었습니다. –

+0

messages.properties 파일은 다른 경우에는 작동하지만 유효성 검사 메시지에서 무시되거나 어떤 경우에도 작동하지 않습니까? ValidationMessages.properties를 찾는 hibernate validator를 사용하고있을 가능성이있다. –

답변

0

"messages.properties"파일을/src/main/resource 디렉토리에 넣으십시오.

관련 문제