JAMES V3 配置文件系列之spring-server.xml
一、概述
spring-server.xml文件是James3.x所有配置文件的切入文件,James3.x主类(org.apache.james.container.spring.Main.java)启动时候会在init方法中载入该配置文件,如下:
publicvoidinit(DaemonContextarg0)throwsException{
context=newJamesServerApplicationContext(newString[]{"META-INF/org/apache/james/spring-server.xml"});
context.registerShutdownHook();
context.start();
}
二、spring-server.xml介绍
附件是spring-server.xml的完整内容,为方便介绍我们将配置文件以一个片段一个片段的介绍。
- 打开Spring的注释功能
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"> <property name="order" value="3" /> </bean>
- 配置JAMES特定配置文件的加载
ConfigurationBeanFactoryPostProcessor实现了org.springframework.beans.factory.config.BeanFactoryPostProcessor接口,实现此接口的Bean,可以在BeanFactory完成依赖注入后进行一些后继处理动作,ConfigurationBeanFactoryPostProcessor就是在完成依赖注入之后将JAMES提供的具体Repository配置文件进行加载。ConfigurationBeanFactoryPostProcessor的beans
属性列表配置的value必须是James的classpath下面的配置文件的文件名,ConfigurationBeanFactoryPostProcessor会根据配置的value在classpath中应用org.apache.commons.configuration.XMLConfiguration类进行配置文件加载,然后应用Spring的BeanDefinitionBuilder和BeanDefinitionRegistry将配置的类进行实例化并注册到Springcontext中.
]
<bean class="org.apache.james.container.spring.bean.factorypostprocessor.ConfigurationBeanFactoryPostProcessor">
<property name="beans">
<map>
<!-- User Repository-->
<entry>
<key>
<!-- 对应 usersrepository.xml 文件配置 -->
<value>usersrepository</value>
</key>
<!-- no alias needed -->
<value></value>
</entry>
<!-- Recipient Rewrite Table-->
<entry>
<key>
<!--对应 recipientrewritetable.xml 文件配置 -->
<value>recipientrewritetable</value>
</key>
<!-- no alias needed -->
<value></value>
</entry>
<!-- Domain List -->
<entry>
<key>
<!--对应 domainlist.xml 文件配置-->
<value>domainlist</value>
</key>
<!-- no alias needed -->
<value></value>
</entry>
<entry>
<key>
<!--对应 usersrepository23.xml 文件配置 -->
<value>usersrepository23</value>
</key>
<!-- no alias needed -->
<value></value>
</entry>
</map>
</property>
</bean>三、结束