以下为spring的配置文件 constellio.xml,对基础服务类进行配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd" default-lazy-init="true"> <util:list id="availablePluginNames"> </util:list> <util:map id="config"> <entry key="supportedLanguages"> <list> <value>en</value> <value>fr</value> </list> </entry> <!-- <entry key="searchableLanguages"> <list> <value>fr</value> <value>en</value> <value>de</value> <value>es</value> <value>it</value> <value>nl</value> </list> </entry> --> <!-- dir paths where it is possible to download a file using DownloadFileServlet --> <!-- Usefull for connector's content url --> <entry key="fileDownloadDirs"> <list> <value></value> </list> </entry> <entry key="defaultConnectorManager"> <value>http://127.0.0.1:8089/huilan-constellio</value> </entry> <entry key="dictionaries"> <value>/WEB-INF/dictionaries</value> </entry> <!-- Search alerts will refer to this url --> <entry key="externalServerUrl"> <value>http://localhost:8089/huilan-constellio</value> </entry> </util:map> <bean id="entityManager" class="com.doculibre.constellio.utils.persistence.ConstellioPersistenceContext" factory-method="getCurrentEntityManager" scope="prototype" /> <bean id="aclServices" class="com.doculibre.constellio.services.ACLServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="analyzerClassServices" class="com.doculibre.constellio.services.AnalyzerClassServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="analyzerServices" class="com.doculibre.constellio.services.AnalyzerServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="authenticationServices" class="com.doculibre.constellio.services.AuthenticationServicesImpl" scope="prototype"> </bean> <bean id="authorizationServices" class="com.doculibre.constellio.services.AuthorizationServicesImpl" scope="prototype"> </bean> <bean id="backupServices" class="com.doculibre.constellio.services.BackupServicesImpl" scope="singleton"> </bean> <bean id="clickLogEntryServices" class="com.doculibre.constellio.services.ClickLogEntryServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="clusteringServices" class="com.doculibre.constellio.services.ClusteringServicesImpl" scope="prototype"> </bean> <bean id="collectionPermissionServices" class="com.doculibre.constellio.services.CollectionPermissionServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="connectorInstanceServices" class="com.doculibre.constellio.services.ConnectorInstanceServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="connectorManagerServices" class="com.doculibre.constellio.services.ConnectorManagerServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="connectorTypeMetaMappingServices" class="com.doculibre.constellio.services.ConnectorTypeMetaMappingServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="connectorTypeServices" class="com.doculibre.constellio.services.ConnectorTypeServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="constellioInitServices" class="com.doculibre.constellio.services.ConstellioInitServicesImpl" scope="singleton"> </bean> <bean id="credentialGroupServices" class="com.doculibre.constellio.services.CredentialGroupServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="elevateServices" class="com.doculibre.constellio.services.ElevateServicesImpl" scope="singleton"> </bean> <bean id="facetServices" class="com.doculibre.constellio.services.FacetServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="featuredLinkIndexHelper" class="com.doculibre.constellio.lucene.impl.FeaturedLinkIndexHelperImpl" scope="singleton"> </bean> <bean id="featuredLinkServices" class="com.doculibre.constellio.services.FeaturedLinkServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="federationServices" class="com.doculibre.constellio.services.FederationServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="fieldTypeClassServices" class="com.doculibre.constellio.services.FieldTypeClassServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="fieldTypeServices" class="com.doculibre.constellio.services.FieldTypeServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="filterClassServices" class="com.doculibre.constellio.services.FilterClassServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="freeTextTagIndexHelper" class="com.doculibre.constellio.lucene.impl.FreeTextTagIndexHelperImpl" scope="singleton"> </bean> <bean id="freeTextTagServices" class="com.doculibre.constellio.services.FreeTextTagServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="groupServices" class="com.doculibre.constellio.services.GroupServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="importExportServices" class="com.doculibre.constellio.services.ImportExportServicesImpl" scope="prototype"> </bean> <bean id="indexFieldServices" class="com.doculibre.constellio.services.IndexFieldServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="loggingServices" class="com.doculibre.constellio.services.LoggingServicesImpl" scope="singleton"> </bean> <bean id="metaNameServices" class="com.doculibre.constellio.services.MetaNameServicesImpl" scope="prototype"> </bean> <bean id="rawContentServices" class="com.doculibre.constellio.services.RawContentServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="recordCollectionServices" class="com.doculibre.constellio.services.RecordCollectionServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="recordServices" class="com.doculibre.constellio.services.RecordServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="searchInterfaceConfigServices" class="com.doculibre.constellio.services.SearchInterfaceConfigServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="searchResultFieldServices" class="com.doculibre.constellio.services.SearchResultFieldServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="searchServices" class="com.doculibre.constellio.services.SearchServicesImpl" scope="prototype"> </bean> <bean id="solrConfigServices" class="com.doculibre.constellio.services.SolrConfigServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="solrServices" class="com.doculibre.constellio.services.SolrServicesImpl" scope="singleton"> </bean> <bean id="skosIndexHelper" class="com.doculibre.constellio.lucene.impl.SkosIndexHelperImpl" scope="singleton"> </bean> <bean id="skosServices" class="com.doculibre.constellio.services.SkosServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="statusServices" class="com.doculibre.constellio.services.StatusServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="categorizationServices" class="com.doculibre.constellio.services.CategorizationServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="synonymServices" class="com.doculibre.constellio.services.SynonymServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="tokenizerClassServices" class="com.doculibre.constellio.services.TokenizerClassServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="userServices" class="com.doculibre.constellio.services.UserServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="keaModelServices" class="com.doculibre.constellio.kea.services.KeaModelServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="favoriteDocumentServices" class="com.doculibre.constellio.services.FavoriteDocumentServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="searchAlertServices" class="com.doculibre.constellio.services.SearchAlertServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> <property name="alertEmailRenderer"> <bean class="com.doculibre.constellio.services.DefaultHtmlAlertEmailRenderer"> <property name="skinEmailColors"> <map> <entry key="red" value="#BE1D1D"/> <entry key="blue" value="#1A5EC3"/> </map> </property> </bean> </property> </bean> <bean id="realisedSearchServices" class="com.doculibre.constellio.services.RealisedSearchServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="favoriteSearchServices" class="com.doculibre.constellio.services.FavoriteSearchServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> <bean id="emailServices" class="com.doculibre.constellio.services.EmailServicesImpl" scope="singleton"> <property name="smtpHost"> <value>relais.videotron.ca</value> <!-- <value>smtp10.bellnet.ca</value>--> </property> <property name="smtpPort"> <value>25</value> </property> <property name="defaultFrom"> <value>baril.francis@gmail.com</value> </property> </bean> <bean id="keaClassificationServices" class="com.doculibre.constellio.kea.services.KeaClassificationServicesImpl" scope="singleton"> </bean> <bean id="autocompleteServices" class="com.doculibre.constellio.services.AutocompleteServicesImpl" scope="singleton"> </bean> <bean id="copyFieldServices" class="com.doculibre.constellio.services.CopyFieldServicesImpl" scope="prototype"> <constructor-arg> <ref bean="entityManager" /> </constructor-arg> </bean> </beans>
接着是ConstellioSpringUtils.java工具类,获取spring容器里面的bean
/** * Constellio, Open Source Enterprise Search * Copyright (C) 2010 DocuLibre inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package com.doculibre.constellio.utils; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.Resource; import com.doculibre.constellio.lucene.impl.FeaturedLinkIndexHelper; import com.doculibre.constellio.lucene.impl.FreeTextTagIndexHelper; import com.doculibre.constellio.lucene.impl.SkosIndexHelper; import com.doculibre.constellio.plugins.PluginFactory; import com.doculibre.constellio.plugins.api.beans.BeanFactoryPlugin; import com.doculibre.constellio.services.ACLServices; import com.doculibre.constellio.services.AnalyzerClassServices; import com.doculibre.constellio.services.AnalyzerServices; import com.doculibre.constellio.services.AuthenticationServices; import com.doculibre.constellio.services.AuthorizationServices; import com.doculibre.constellio.services.AutocompleteServices; import com.doculibre.constellio.services.BackupServices; import com.doculibre.constellio.services.CategorizationServices; import com.doculibre.constellio.services.ClickLogEntryServices; import com.doculibre.constellio.services.ClusteringServices; import com.doculibre.constellio.services.CollectionPermissionServices; import com.doculibre.constellio.services.ConnectorInstanceServices; import com.doculibre.constellio.services.ConnectorManagerServices; import com.doculibre.constellio.services.ConnectorTypeMetaMappingServices; import com.doculibre.constellio.services.ConnectorTypeServices; import com.doculibre.constellio.services.ConstellioInitServices; import com.doculibre.constellio.services.CopyFieldServices; import com.doculibre.constellio.services.CredentialGroupServices; import com.doculibre.constellio.services.DistributedSolrServerServices; import com.doculibre.constellio.services.ElevateServices; import com.doculibre.constellio.services.EmailServices; import com.doculibre.constellio.services.FacetServices; import com.doculibre.constellio.services.FavoriteDocumentServices; import com.doculibre.constellio.services.FavoriteSearchServices; import com.doculibre.constellio.services.FeaturedLinkServices; import com.doculibre.constellio.services.FederationServices; import com.doculibre.constellio.services.FieldTypeClassServices; import com.doculibre.constellio.services.FieldTypeServices; import com.doculibre.constellio.services.FilterClassServices; import com.doculibre.constellio.services.FreeTextTagServices; import com.doculibre.constellio.services.GroupServices; import com.doculibre.constellio.services.ImportExportServices; import com.doculibre.constellio.services.IndexFieldServices; import com.doculibre.constellio.services.LoggingServices; import com.doculibre.constellio.services.MetaNameServices; import com.doculibre.constellio.services.RawContentServices; import com.doculibre.constellio.services.RealisedSearchServices; import com.doculibre.constellio.services.RecordCollectionServices; import com.doculibre.constellio.services.RecordServices; import com.doculibre.constellio.services.SearchAlertServices; import com.doculibre.constellio.services.SearchInterfaceConfigServices; import com.doculibre.constellio.services.SearchResultFieldServices; import com.doculibre.constellio.services.SearchServices; import com.doculibre.constellio.services.SkosServices; import com.doculibre.constellio.services.SolrConfigServices; import com.doculibre.constellio.services.SolrServices; import com.doculibre.constellio.services.StatusServices; import com.doculibre.constellio.services.SynonymServices; import com.doculibre.constellio.services.TokenizerClassServices; import com.doculibre.constellio.services.UserServices; public class ConstellioSpringUtils { private static ApplicationContext applicationContext; private static void loadApplicationContext() { if (applicationContext == null) { applicationContext = new ClassPathXmlApplicationContext("constellio.xml"); } } public static void setApplicationContext(ApplicationContext applicationContext) { ConstellioSpringUtils.applicationContext = applicationContext; } @SuppressWarnings("unchecked") public static final <T extends Object> T getBean(String name) { loadApplicationContext(); return (T) applicationContext.getBean(name); } @SuppressWarnings("unchecked") public static final <T extends Object> T getPluggableBean(String name) { T bean; BeanFactoryPlugin beanFactoryPlugin = PluginFactory.getPlugin(BeanFactoryPlugin.class); if (beanFactoryPlugin != null) { bean = (T) beanFactoryPlugin.getBean(name); } else { bean = (T) getBean(name); } return bean; } public static Resource[] getResources(String locationPattern) { loadApplicationContext(); try { return applicationContext.getResources(locationPattern); } catch (IOException e) { throw new RuntimeException(e); } } public static Map<String, Object> getConfig() { return getBean("config"); } public static String getDictionaries() { return (String) getConfig().get("dictionaries"); } public static String getExternalServerURL() { return (String) getConfig().get("externalServerUrl"); } @SuppressWarnings("unchecked") public static List<String> getFileDownloadDirs() { return (List<String>) getConfig().get("fileDownloadDirs"); } public static URL getDefaultConnectorManagerURL() { String defaultConnectorManager = (String) getConfig().get("defaultConnectorManager"); try { return new URL(defaultConnectorManager); } catch (MalformedURLException e) { throw new RuntimeException(e); } } @SuppressWarnings("unchecked") public static List<Locale> getSupportedLocales() { List<Locale> supportedLocales = new ArrayList<Locale>(); List<String> supportedLanguages = (List<String>) getConfig().get("supportedLanguages"); for (String supportedLanguage : supportedLanguages) { supportedLocales.add(new Locale(supportedLanguage)); } return supportedLocales; } @SuppressWarnings("unchecked") public static List<Locale> getSearchableLocales() { List<Locale> searchableLocales = new ArrayList<Locale>(); List<String> searchableLanguages = (List<String>) getConfig().get("searchableLanguages"); if (searchableLanguages != null) { for (String searchableLanguage : searchableLanguages) { searchableLocales.add(new Locale(searchableLanguage)); } } return searchableLocales; } public static Locale getDefaultLocale() { return getSupportedLocales().get(0); } public static ACLServices getACLServices() { return getPluggableBean("aclServices"); } public static List<String> getAvailablePluginNames() { return getBean("availablePluginNames"); } public static AnalyzerClassServices getAnalyzerClassServices() { return getPluggableBean("analyzerClassServices"); } public static AnalyzerServices getAnalyzerServices() { return getPluggableBean("analyzerServices"); } public static AuthenticationServices getAuthenticationServices() { return getPluggableBean("authenticationServices"); } public static AuthorizationServices getAuthorizationServices() { return getPluggableBean("authorizationServices"); } public static BackupServices getBackupServices() { return getPluggableBean("backupServices"); } public static ClickLogEntryServices getClickLogEntryServices() { return getPluggableBean("clickLogEntryServices"); } public static ClusteringServices getClusteringServices() { return getPluggableBean("clusteringServices"); } public static ConnectorInstanceServices getConnectorInstanceServices() { return getPluggableBean("connectorInstanceServices"); } public static ConnectorManagerServices getConnectorManagerServices() { return getPluggableBean("connectorManagerServices"); } public static ConnectorTypeMetaMappingServices getConnectorTypeMetaMappingServices() { return getPluggableBean("connectorTypeMetaMappingServices"); } public static ConnectorTypeServices getConnectorTypeServices() { return getPluggableBean("connectorTypeServices"); } public static ConstellioInitServices getConstellioInitServices() { return getPluggableBean("constellioInitServices"); } public static CredentialGroupServices getCredentialGroupServices() { return getPluggableBean("credentialGroupServices"); } public static ElevateServices getElevateServices() { return getPluggableBean("elevateServices"); } public static FacetServices getFacetServices() { return getPluggableBean("facetServices"); } public static FeaturedLinkIndexHelper getFeaturedLinkIndexHelper() { return getPluggableBean("featuredLinkIndexHelper"); } public static FeaturedLinkServices getFeaturedLinkServices() { return getPluggableBean("featuredLinkServices"); } public static FederationServices getFederationServices() { return getPluggableBean("federationServices"); } public static FieldTypeClassServices getFieldTypeClassServices() { return getPluggableBean("fieldTypeClassServices"); } public static FieldTypeServices getFieldTypeServices() { return getPluggableBean("fieldTypeServices"); } public static FilterClassServices getFilterClassServices() { return getPluggableBean("filterClassServices"); } public static FreeTextTagServices getFreeTextTagServices() { return getPluggableBean("freeTextTagServices"); } public static FreeTextTagIndexHelper getFreeTextTagIndexHelper() { return getPluggableBean("freeTextTagIndexHelper"); } public static GroupServices getGroupServices() { return getPluggableBean("groupServices"); } public static CollectionPermissionServices getCollectionPermissionServices() { return getPluggableBean("collectionPermissionServices"); } public static ImportExportServices getImportExportServices() { return getPluggableBean("importExportServices"); } public static IndexFieldServices getIndexFieldServices() { return getPluggableBean("indexFieldServices"); } public static MetaNameServices getMetaNameServices() { return getPluggableBean("metaNameServices"); } public static RawContentServices getRawContentServices() { return getPluggableBean("rawContentServices"); } public static RecordCollectionServices getRecordCollectionServices() { return getPluggableBean("recordCollectionServices"); } public static RecordServices getRecordServices() { return getPluggableBean("recordServices"); } public static SearchInterfaceConfigServices getSearchInterfaceConfigServices() { return getPluggableBean("searchInterfaceConfigServices"); } public static LoggingServices getLoggingServices() { return getPluggableBean("loggingServices"); } public static SearchResultFieldServices getSearchResultFieldServices() { return getPluggableBean("searchResultFieldServices"); } public static SearchServices getSearchServices() { return getPluggableBean("searchServices"); } public static SkosIndexHelper getSkosIndexHelper() { return getPluggableBean("skosIndexHelper"); } public static SkosServices getSkosServices() { return getPluggableBean("skosServices"); } public static SolrServices getSolrServices() { return getPluggableBean("solrServices"); } public static SolrConfigServices getSolrConfigServices() { return getPluggableBean("solrConfigServices"); } public static StatusServices getStatusServices() { return getPluggableBean("statusServices"); } public static CategorizationServices getCategorizationServices() { return getPluggableBean("categorizationServices"); } public static SynonymServices getSynonymServices() { return getPluggableBean("synonymServices"); } public static TokenizerClassServices getTokenizerClassServices() { return getPluggableBean("tokenizerClassServices"); } public static UserServices getUserServices() { return getPluggableBean("userServices"); } public static AutocompleteServices getAutocompleteServices() { return getPluggableBean("autocompleteServices"); } public static CopyFieldServices getCopyFieldServices() { return getPluggableBean("copyFieldServices"); } public static FavoriteDocumentServices getFavoriteDocumentServices() { return getPluggableBean("favoriteDocumentServices"); } public static SearchAlertServices getSearchAlertServices() { return getPluggableBean("searchAlertServices"); } public static RealisedSearchServices getRealisedSearchServices() { return getPluggableBean("realisedSearchServices"); } public static FavoriteSearchServices getFavoriteSearchServices() { return getPluggableBean("favoriteSearchServices"); } public static EmailServices getEmailServices() { return getPluggableBean("emailServices"); } public static DistributedSolrServerServices getDistributedSolrServerServices() { return getPluggableBean("distributedSolrServerServices"); } }