2013-12-18 3 views
0

나는 내 응용 프로그램 컨텍스트 XML 파일이 포함 바람둥이 6을 사용하고 파일을 찾을 수 없습니다 무시 :봄의 특성이 예외

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" value="file:#{contextParameters['my-filename']}"/> 
</bean> 

내 web.xml 파일 :

<context-param> 
    <param-name>my-filename</param-name> 
    <param-value></param-value> 
</context-param> 

나는 다음을 수행 할 :

  • 사용자가 tomcat 서버를 실행할 때 처음에는 my-filename의 값이 비어 있습니다. 사용자가 confi로 리디렉션되어야합니다. g 페이지에서 속성 파일 위치를 설정할 수있는 곳은 my-filename 값입니다.
  • save를 클릭하면 web.xml 파일을 업데이트하고 tomcat 서버를 다시 시작합니다.

이제 FileNotFoundException 예외가 발생하며 계속되지 않습니다. 파일에서 예외를 발견하지 못했고 사용자를 구성 페이지로 리디렉션하는 방법을 알 수 있습니까?

+0

경로를 확인하십시오 : 기본값을 사용하고있는 경우, 확인 후

<bean id="configLocation" class="java.lang.String"> <constructor-arg type="java.lang.String" value="file:#{contextParameters['my-filename']:./default-empty-file.properties}"/> </bean> <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" ref="configLocation"/> </bean> 

을 그리고 주어진 파일 이름의. 컴파일러는 지정된 path.so에서 파일을 찾을 수 없습니다. 올바르게 주어 졌는지 확인하십시오. – Lijo

+2

@ 404 질문을 다시 읽어야합니다. – eis

+2

[javadoc] (http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/config/) 읽었습니까? PropertyPlaceholderConfigurer.html)? 간단히'ignoreResourceNotFound' 속성을 설정하십시오. –

답변

0

당신은 만들 필요가 일부 빈 파일에 AA 기본값 가리키는을 사용할 수 있어야합니다 :

@Autowired 
@Qualifier("configLocation") 
String configLocation; 

final static String EMPTY_CONFIG_LOCATION = "file:./default-empty-file.properties"; 

@RequestMapping(method = RequestMethod.GET) 
public String SomeAction(){ 
    if (EMPTY_CONFIG_LOCATION.equals(configLocation)) { 
     // redirect 
     return "redirect:configPage"; 
    } else { 
     // do the normal stuff 
    } 
} 
+0

컨트롤러에서 @Share ...? 아니면 봄용 응용 프로그램을 설치 했습니까? – eis