Spring-DM可能不支持較新版本的Spring,但Eclipse Gemini Blueprint會。如果您可以使用Spring 3.1.x或更高版本和Blueprint,則可能可以使Spring配置文件正常工作。一種方法是使用extend the Blueprint Extender bundle自己實現OsgiApplicationContextCreator
,根據需要配置ApplicationContext
Environment
活動配置文件。例如,請考慮以下自定義BlueprintContainerCreator
實現:
public class MyOsgiApplicationContextCreator extends BlueprintContainerCreator {
@Override
public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(
BundleContext bundleContext) throws Exception {
DelegatedExecutionOsgiBundleApplicationContext applicationContext = super
.createApplicationContext(bundleContext);
if (null == applicationContext) {
// non-spring/blueprint bundles will not build an ApplicationContext
return null;
}
// determine environment profile here...
applicationContext.getEnvironment().setActiveProfiles("myProfile");
return applicationContext;
}
}
您需要把這個到附在藍圖擴展包片段束。執行以下操作:
您需要創建一個包含三個文件的包:META-INF/MANIFEST.MF,META-INF/spring/extender/extender.xml(可以將xml文件命名爲一個xml擴展名,但必須位於META-INF/spring/extender文件夾中)以及您的實現。您的MANIFEST.MF文件將需要包含org.eclipse.gemini.blueprint.extender
的OSGi清單頭文件碎片主機。如果您正在使用Maven的捆綁,插件,插件配置會是這個樣子:
...
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.5</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Fragment-Host>org.eclipse.gemini.blueprint.extender</Fragment-Host>
<Export-Package>your.package,!*</Export-Package>
<Import-Package>org.osgi.framework,org.springframework.core.env,!*</Import-Package>
</instructions>
</configuration>
</plugin>
...
你extender.xml文件將需要使用的applicationContextCreator
一個名稱來定義您的自定義OsgiApplicationContextCreator
豆。該文件可能如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<util:properties id="extenderProperties">
<prop key="shutdown.wait.time">30000</prop>
</util:properties>
<bean id="applicationContextCreator" class="your.package.MyOsgiApplicationContextCreator"/>
</beans>
然後將該軟件包部署到您的環境中。您可能需要重新啓動Blueprint OSGi軟件包(或您的服務器),具體取決於與Blueprint軟件包相關的此片段軟件包的安裝順序。