私は、プラグインを動的にロードできるフレームワークを作成しようとしています。このロード・プロセスの1つのステップは、プロパティー・ファイル "properties.plugin"をロードすることです。PropertyPlaceholderConfigurerにロードしたいのですが、これはGenericApplicationContextが使用するように設定されているクラスローダーとは異なるクラスローダーを使用しているようです。カスタムクラスローダーを持つPropertyPlaceholderConfigurer
コンテキストを作成するための私のコードは:上記のコードで
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;
}
}
クラスローダは、起動時に設定されます。
次のように豆を設置している:私はctx.refresh(呼び出すとき
<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は単に、後のコードで、私はプロパティを見つけることができなかったと言ってログメッセージを参照してください)PropertyPlaceholderConfigurer
を拡張
次のコード/properties.plugin
classLoader.getResource("properties/properties.plugin");
コンテキストにクラスローダーを設定する直前に追加すると動作します。
私はclasspath:properties/properties.plugin、properties.plugin、classpath *:properties.pluginも試しました。
このPropertyPlaceholderConfigurerがctxで設定されたものとは異なるクラスローダーを使用している場合は、それが使用するクラスローダーを設定する方法がありますか?
setClassLoaderメソッドが表示されません。