Skip to content

Home

Introduction

Development

Overview

IDEs

Services

Service manager

API Explorer

Integrate package Spring context

TORO Integrate works on top of Spring and exposes much of the neat features that come with it to integration developers. In this section of the documentation, we will discuss one of these re-exposed features: Spring IoC containers.

Advantages

According to the Spring documentation:

The interface org.springframework.context.ApplicationContext represents the Spring IoC container and is responsible for instantiating, configuring, and assembling . . . beans. The container gets its instructions on what objects to instantiate, configure, and assemble by reading configuration metadata. The configuration metadata is represented in XML, Java annotations, or Java code. It allows you to express the objects that compose your application and the rich interdependencies between such objects.

TORO Integrate allows developers to define multiple configuration metadata in Integrate packages and have Spring read them (as long as they are properly referenced) in order to create Spring beans and make them available for package-wide use.

Simply put, a Spring bean is a Java object whose lifecycle is managed by a Spring IoC container, the environment in which Spring beans live. Spring beans defined in TORO Integrate are initialized and attached to the Spring context during package start-up, and will be available until the package is stopped (unless an error during initialization occurs).

Why should I let Spring manage my objects?

Objects that would be consumed or reused for composition throughout your project should ideally be instantiated as Spring beans. By doing so, you won't have to re-instantiate these objects whenever you need to use any of their methods.

It is very important to decide which objects should be instantiated as Spring beans as not all objects should be part of the Spring context (e.g. exceptions, enums, static utility classes).

Cross-package bean availability

As of the current version, beans added to the Spring context of a package are accessible across other started packages as well. This behavior may be subject to change in future versions of TORO Integrate.

Since Spring beans are just Spring-managed Java objects, their methods are still considered services in TORO Integrate; much like Groovy methods are Groovy services. This also means it's possible to select Spring bean methods in the service picker.

Service picker

The service picker appears when selecting a service for use with a component; usually the service which is invoked when conditions are met, such as when an endpoint gets triggered.

Procedures

There are multiple ways to define Spring beans. The instructions below will describe how to create XML-based configuration metadata:

  1. Under your target Integrate package's /conf directory, create an XML file. This XML file will contain the Spring bean definitions. It is possible to create more than one configuration metadata in order to organize your beans better. This file has no naming restrictions; although ideally, it should be named so that it is easy to identify.
  2. Edit the newly created XML file and define your Spring beans there. To help you get started fast and easy, here's a boilerplate from the Spring documentation which you can copy and paste unto the file; simply plug your <bean /> definitions as you like afterwards.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    <?xml version="1.0" encoding="UTF-8"?>
    <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.xsd">
    
        <!-- Define your beans here -->
    
    </beans>
    

    XML schema-based configuration

    See Spring's page on XML schema-based configuration for more examples and information about configuring Spring via XML.

  3. Update the package's esb-package.xml file and add a reference to the XML file you created earlier by adding a new <context-file>${value}</context-file> element under the <spring-contexts> tag; ${value} being the base name of the XML file created earlier. For example:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <esb-package context-path="/examples"
                 documentation-page="http://docs.torocloud.com/toro-integrate/"
                 id="io.toro.integrate.examples"
                 version="1"
                 enabled="true"
                 readOnly="false"
                 autoStart="true">
    <depends-on-packages/>
    <startup-services/>
    <shutdown-services/>
    <jms-destinations/>
    <spring-contexts>
        <context-file>dao-beans.xml</context-file>
        <context-file>service-beans.xml</context-file>
    </spring-contexts>
    <endpoints/>
    <solr-cores/>
    </esb-package>
    
  4. Restart the package for the context to be re-initialized.