2013-02-26 2 views
2

스프링 및 OSGi 기반 응용 프로그램을 개발하는 동안 문제가 발생했습니다. 내 응용 프로그램에서는 스프링 beans 프로파일을 사용하고 싶지만 강제로 특정 프로파일을 사용하는 방법을 모르겠습니다. 나는 한 번 봄 프로파일을 사용했지만 웹 애플리케이션에서는이 튜토리얼을 따랐다 : http://java.dzone.com/articles/spring-31-environment-profiles. 스프링 DM이 지원하는 경우스프링 빈 프로필 및 OSGI

하지만 나는 확실하지 않다 ApplicationContextInitializer

답변

2

의 일부 상당을 찾을 수 있기 때문에,은 OSGi 환경에서이 작업을 수행하는 방법을 몰라과 그 이전의 봄을 기반으로. 스프링 프로파일은 스프링 -3.1에 추가되었는데, 스프링 프로파일은 죽은 프로젝트였던 지 오래되었다. http://www.springsource.org/osgi

0

스프링 DM은 새 버전의 스프링을 지원하지 않지만 Eclipse Gemini Blueprint은 지원하지 않습니다. Spring 3.1.x 이상 및 Blueprint를 사용할 수 있다면 Spring 프로필이 작동 할 수 있습니다. 이를 수행하는 한 가지 방법은 ApplicationContextEnvironment 활성 프로필을 적합하게 구성하는 OsgiApplicationContextCreator을 직접 구현하여 extend the Blueprint Extender bundle입니다. 당신은 청사진 확장 번들에 부착 된 조각 번들이 점을 넣을 필요가

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; 
    } 
} 

예를 들어, 다음 사용자 정의 BlueprintContainerCreator 구현을 고려한다.

META-INF/MANIFEST.MF, META-INF/spring/extender/extender.xml (xml 파일의 이름은 다음과 같이 3 개의 파일로 묶음을 만들어야합니다. xml 확장자이지만 META-INF/spring/extender 폴더에 있어야 함) 및 OsgiApplicationContextCreator 구현. MANIFEST.MF 파일은 OSGi 매니페스트 헤더 Fragment-Host org.eclipse.gemini.blueprint.extender을 포함해야합니다. 당신은 받는다는 - 번들 플러그인을 사용하는 경우, 플러그인 구성은 다음과 같이 보일 것입니다 :

... 
<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 번들과 관련하여이 조각 번들이 설치된 순서에 따라 Blueprint OSGi 번들 (또는 서버)을 다시 시작해야 할 수도 있습니다.