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软件包相关的此片段软件包的安装顺序。