2012-02-27 3 views
0

플러그인을 동적으로로드 할 수있는 프레임 워크를 작성하려고합니다. 이 로딩 프로세스의 한 단계는 "properties.plugin"속성 파일을로드하는 것입니다. 그러나 PropertyPlaceholderConfigurer에로드하고 싶습니다. 그러나이 클래스는 GenericApplicationContext가 사용하도록 설정된 클래스 로더와 다른 클래스 로더를 사용합니다. 컨텍스트를 만드는PropertyPlaceholderConfigurer with custom classloader

내 코드 : 위의 코드에서

GenericApplicationContext ctx = new GenericApplicationContext(); 
    if(classLoader !=null) 
     ctx.setClassLoader(classLoader); 
    ctx.getDefaultListableBeanFactory().setAllowBeanDefinitionOverriding(false); 

    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); 
    xmlReader.setBeanClassLoader(classLoader); 
    int totalBeanCount = 0; 
    List<Resource> processedResources = new ArrayList<Resource>(resources.length); 
    for(Resource r:resources) 
    { 
     try 
     { 
      int loadedBeanCount = xmlReader.loadBeanDefinitions(r); 
      totalBeanCount += loadedBeanCount; 
      processedResources.add(r); 

     } 
     catch(BeanDefinitionStoreException e) 
     { 

      throw e; 
     } 
    } 

classLoader가이 시작 최대로 설정됩니다.

<bean name="ReloadedPropertiesPlaceholderConfigurer" class="myProject.MyPropertyPlaceholderConfigurer" > 
    <property name="locationNames" ref="locationNamesList" /> 
    <property name="ignoreUnresolvablePlaceholders" value="true"/> 
</bean> 

<bean name="locationNamesList" class="java.util.ArrayList"> 
    <constructor-arg> 
     <list> 
      <value>properties/properties.plugin</value> 
     </list> 
    </constructor-arg> 
</bean> 

myProject.MyPropertyPlaceholderConfigurer 단순히

내가 ctx.refresh을 (전화 PropertyPlaceholderConfigurer와

을 확장) 나중에 내가 속성을 찾을 수 없습니다라는 로그 메시지를 볼 수있는 코드에서 다음과 같이

빈은 설정입니다

다음 코드 /properties.plugin

classLoader.getResource("properties/properties.plugin"); 

문맥에 클래스 로더를 설정하기 바로 전에 추가하면 작동합니다.

나는 또한 classpath : properties/properties.plugin, properties.plugin, classpath * : properties.plugin을 시도했다.

이 PropertyPlaceholderConfigurer가 ctx에 설정된 것과 다른 클래스 로더를 사용하고 있으며 그렇다면 클래스 로더를 설정하는 방법이 있습니까?

setClassLoader 메서드가 표시되지 않습니다.

답변

0
Thread.currentThread().setContextClassLoader(classLoader); 

문맥에서 설정된 클래스 로더 대신이 클래스 로더를 사용해야하는 것처럼 보입니다.

관련 문제