이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 2. Dependency Injection Frameworks


Abstract

Red Hat JBoss Fuse supports two alternative dependency injection frameworks: Spring and OSGi blueprint. These frameworks are fully integrated with the Red Hat JBoss Fuse container, so that Spring XML files and blueprint XML files are automatically activated at the same time the corresponding bundle is activated.

2.1. Spring and Blueprint Frameworks

Overview

The OSGi framework allows third-party frameworks to be piggybacked on top of it. In particular, Red Hat JBoss Fuse enables the Spring framework and the blueprint framework, by default. In the case of the Spring framework, OSGi automatically activates any Spring XML files under the META-INF/spring/ directory in a JAR, and Spring XML files can also be hot-deployed to the ESBInstallDir/deploy directory. In the case of the blueprint framework, OSGi automatically activates any blueprint XML files under the OSGI-INF/blueprint/ directory in a JAR, and blueprint XML files can also be hot-deployed to the ESBInstallDir/deploy directory.

Prefer Blueprint over Spring-DM

The Blueprint container is now the preferred framework for instantiating, registering, and referencing OSGi services, because this container has now been adopted as an OSGi standard. This ensures greater portability for your OSGi service definitions in the future.
Spring Dynamic Modules (Spring-DM) provided much of the original impetus for the definition of the Blueprint standard, but should now be regarded as obsolescent. Using the Blueprint container does not prevent you from using the Spring framework: the latest version of Spring is compatible with Blueprint.

Configuration files

There are two kinds of file that you can use to configure your project:
  • Spring configuration—in the standard Maven directory layout, Spring XML configuration files are located under ProjectDir/src/main/resources/META-INF/spring.
  • Blueprint configuration—in the standard Maven directory layout, blueprint XML configuration files are located under ProjectDir/src/main/resources/OSGI-INF/blueprint.
If you decide to use the blueprint configuration, you can embed camelContext elements in the blueprint file, as described in the section called “Blueprint configuration file”.

Prerequisites for blueprint configuration

If you decide to configure your Apache Camel application using blueprint, you must ensure that the camel-blueprint feature is installed. If necessary, install it by entering the following console command:
JBossFuse:karaf@root> features:install camel-blueprint
Copy to Clipboard Toggle word wrap

Spring configuration file

You can deploy a camelContext using a Spring configuration file, where the root element is a Spring beans element and the camelContext element is a child of the beans element. In this case, the camelContext namespace must be http://camel.apache.org/schema/spring.
For example, the following Spring configuration defines a route that generates timer messages every two seconds, sending the messages to the ExampleRouter log (which get incorporated into the console log file, InstallDir/data/log/fuse.log):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       >

  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="timer://myTimer?fixedRate=true&amp;period=2000"/>
      <to uri="log:ExampleRouter"/>
    </route>
  </camelContext>

</beans>
Copy to Clipboard Toggle word wrap
It is not necessary to specify schema locations in the configuration. But if you are editing the configuration file with an XML editor, you might want to add the schema locations in order to support schema validation and content completion in the editor. For the preceding example, you could specify the schema locations as follows:
<beans xmlns="http://www.springframework.org/schema/beans"
       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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
    ...
Copy to Clipboard Toggle word wrap

Blueprint configuration file

Before deploying routes in a blueprint configuration file, check that the camel-blueprint feature is already installed.
You can deploy a camelContext using a blueprint configuration file, where the root element is blueprint and the camelContext element is a child of the blueprint element. In this case, the camelContext namespace must be http://camel.apache.org/schema/blueprint.
For example, the following blueprint configuration defines a route that generates timer messages every two seconds, sending the messages to the ExampleRouter log (which get incorporated into the console log file, InstallDir/data/log/fuse.log):
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    >

  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
    <route>
      <from uri="timer://myTimer?fixedRate=true&amp;period=2000"/>
      <to uri="log:ExampleRouter"/>
    </route>
  </camelContext>

</blueprint>
Copy to Clipboard Toggle word wrap
Note
Blueprint is a dependency injection framework, defined by the OSGi standard, which is similar to Spring in many respects. For more details about blueprint, see Section 16.1, “The Blueprint Container”.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat