programing

OSGi에서 스프링 부트를 사용할 수 있습니까?그렇지 않은 경우 OSGi Spring Boot을 사용할 계획이 있습니까?

megabox 2023. 2. 28. 23:23
반응형

OSGi에서 스프링 부트를 사용할 수 있습니까?그렇지 않은 경우 OSGi Spring Boot을 사용할 계획이 있습니까?

OSGi에서 스프링 부트를 사용할 수 있습니까?그렇지 않다면 OSGi 스프링 부트(Apache Felix 또는 Eclipse Equinox)를 사용할 계획이 있습니까?클라우드 애플리케이션은 OSGi와 같이 고도로 모듈화되어 업데이트 가능해야 한다고 생각합니다.

,, 달, 달, 달, 달, 습,Spring BootOSGI를 사용하다

에서 Spring Boot로 .jar, OSGI로의 키 os 、 OSGI 의 packagingbundle.

★★★★★★★★★를 사용하고 있는 경우는Maven 하면 .org.apache.felix:maven-bundle-plugin~의미로Spring Boot 무효OSGI 묶음, , 묶음, , 묶음, 묶음, 묶음, 묶음, 묶음, 묶음, 묶음, 묶음, 묶음 중 .bnd을 사용법 '아까부터'로 할 수 요.maven-bundle-plugin 「」, 「」에 의한 설정<Embed-Dependency>.

, 들들시들 the the the the the the the the the the the로 시작해야 합니다.Spring Boot스프링 부츠에서 부츠를 시작하는 입니다.BundleActivator:

@Import(AppConfig.class)
@SpringBootConfiguration
@EnableAutoConfiguration
public class SpringBootBundleActivator implements BundleActivator {

    ConfigurableApplicationContext appContext;

    @Override
    public void start(BundleContext bundleContext) {
        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
        appContext = SpringApplication.run(SpringBootBundleActivator.class);
    }

    @Override
    public void stop(BundleContext bundleContext) {
        SpringApplication.exit(appContext, () -> 0);
    }
}

, OSGI 를 해 번들을 .Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());입니다.Spring이치노

데모 레포(https://github.com/StasKolodyuk/osgi-spring-boot-demo에서 확인할 수 있습니다.

별도 답변으로 게재할 가치가 있다고 생각합니다(모두의 코멘트를 읽는 것은 아닙니다).

@StasKolodyuk의 뛰어난 솔루션을 통해 OSGI 환경에서 Spring Boot 애플리케이션을 실행할 수 있습니다.

단, 제한사항: OSGI에서 실행할 경우 패키지 스캔이 지원되지 않기 때문에 Spring Boot의 주석 자동 매핑은 작동하지 않습니다.

마지막으로 코드로부터 컴포넌트를 자동적으로 취득하는 Spring Boot 앱을 OSGI(Karaf에서 테스트 완료)로 실행할 수 있는 또 다른 트릭이 있습니다.

기능 예는 https://github.com/dimmik/osgi-spring-boot-demo 에서 구할 수 있습니다.

이 트릭은 Spring Application 인스턴스에 적절한 ResourcePattern Resolver를 제공하는 것입니다.

package by.kolodyuk.osgi.springboot;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.osgi.io.OsgiBundleResourcePatternResolver;

@SpringBootApplication
public class SpringBootBundleActivator implements BundleActivator {

    ConfigurableApplicationContext appContext;

    @Override
    public void start(BundleContext bundleContext) {
        // Set context classloader (main trick, to enable SpringBoot start at the first place)
        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
        // trick to enable scan: get osgi resource pattern resolver
        OsgiBundleResourcePatternResolver resourceResolver = new OsgiBundleResourcePatternResolver(bundleContext.getBundle());
        // and provide it to spring application
        appContext = new SpringApplication(resourceResolver, SpringBootBundleActivator.class).run();
    }

    @Override
    public void stop(BundleContext bundleContext) {
        SpringApplication.exit(appContext, () -> 0);
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringBootBundleActivator.class);
    }
}

OSGi를 Spring Boot Application에 삽입하여 프레임워크에서 응용 프로그램의 일부에 액세스할 수 있도록 하는 방법이 있습니다.OSGi 를 프로그래밍 방식으로 기동하는 방법에 대해서는, https://stackoverflow.com/a/4673904/173101 를 참조해 주세요.

그러나 일반적으로 "OSGi-Support"와 같은 것은 없습니다.OSGi는 모든 Java 애플리케이션에 통합할 수 있습니다.또, 그 반대의 경우도, 모든 Java 코드(Spring-Boot 애플리케이션)를 OSGi 번들로 패키지화해, OSGi 컨테이너내에서 기동할 수 있습니다(단, 별로 의미가 없는 경우도 있습니다).

OSGi에 Spring Boot을 도입하는 데는 충분한 이유가 있습니다.그 주된 이유는 퍼포먼스입니다.특히 Spring Boot 서비스가 기능 서비스(시작, 결과 반환, 종료 등)인 경우 스타트업 퍼포먼스입니다.Spring Boot에서 현재 베타 테스트 중인 애플리케이션은 Equinox에 배포된 후 3.5초 이내에 시작됩니다.OSGi 기반 응용 프로그램 또는 Java EE 서버로의 통합이 다른 이유일 수 있습니다.

단, Spring Boot에서 OSGi를 실행할 수도 있습니다.퍼포먼스상으로는 단순히 크기가 작다는 이유만으로 Concierge를 OSGi 구현으로 선호합니다(단, 어플리케이션이 큰 구현의 모든 기능을 필요로 하지 않는 한).

다른 방법으로는 Spring Boot 어플리케이션에서 사용되는 Spring 라이브러리를 (WSO2에서) MSF4J로 랩하는 방법이 있습니다.이 방법은 많은 작업이 필요하지 않고 메모리 사용량의 1/10으로 부팅 속도를 10배 높일 수 있습니다.

아니요, OSGi는 지원하지 않습니다.Spring Boot은 모든 의존관계 및 실행 가능한 JAR에 포함된 서블릿 컨테이너를 패키지화된 애플리케이션으로 마이크로 서비스를 작성하는 것을 목표로 하고 있습니다.따라서 OSGi 컨테이너를 제공 및 구성할 필요 없이 고도로 모듈화되어 업데이트 가능합니다.

스프링 부트 - 일반적인 스프링 부트 앱은 osgi에는 조금 '뚱뚱'합니다.starter-web 또는 jersey를 사용하는 경우 포트는 osgi 런타임에 상주하는 모든 osgi "서비스"에 의해 공유되므로 포트 결정 스킴을 추가해야 합니다.

스프링 부트를 줄일 수 없는 한 피하는 것이 좋습니다.스프링 부트 지방 항아리/전쟁이 서브 클래스 로더를 기동하기 때문입니다.이것은 표준적인 osgi 클래스 로더 문제(com.whatter)에 대해 혼란스러울 때 단순해지지 않습니다.어떤 오브젝트MyClass는 다른 모든 번들로 내보내는 번들에서 "Import"되지 않기 때문에 다른 번들 및 클래스로더에서는 동일하지 않습니다.) 번들 간 서비스 통신에 대한 요건이 있는 경우.

웹 리스너가 필요 없고 표준 Import에 포함되지 않은 오브젝트(코어 Java se 클래스 등)를 사용하는 번들 간 서비스인터페이스는 모두 사용하지 않도록 하기 위해 다음 가이드를 권장합니다.라이프 사이클만 신경 쓰시죠?

마이크로 서비스 패턴을 고수하고 REST API를 통해 스프링 부트 서비스와 통신하는 별도의 애플리케이션으로 OSGI 앱을 실행하는 것이 좋습니다.OSGI 애플리케이션 측에서는 Jetty/Jersey 등을 사용하여 REST 통신을 쉽게 관리할 수 있습니다.

언급URL : https://stackoverflow.com/questions/30881786/can-spring-boot-be-used-with-osgi-if-not-any-plans-to-have-an-osgi-spring-boot

반응형