///////////////////////////////////////////////////////////////
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
///////////////////////////////////////////////////////////////

[[library-spring, Spring Integration Library]]
= Spring Integration =

[devstatus]
--------------
source=libraries/spring/dev-status.xml
--------------

include::../../build/docs/buildinfo/artifact.txt[]

== Using Spring Framework in Apache Zest™ ==
Zest™ supports that Spring Application Context is imported into the Zest™ runtime, and the declared Spring
beans will be available as Zest™ services. The most important things to remember are;

    1. Only Spring Singletons are currently supported.
    2. One ApplicationContext per Zest™ Module.
    3. The Zest™ service will be given the same name as the Spring Bean name.
    4. Zest™ Configuration is not reacbable from the Spring bean (kind of obvious).

[snippet,java]
----
source=libraries/spring/src/test/java/org/qi4j/library/spring/importer/Qi4jImportServiceTest.java
tag=import
----

== Using Apache Zest™ in Spring Framework ==
It is also possible to run a Zest™ Application as a Spring Bean and export its Services to Spring.

Steps to export Zest™ service:

    1. Create spring BeanFactory service of qi4j services to export.
    2. Create a class that extends Qi4jApplicationBootstrap.
    3. Sets the layer and module that register BeanFactory service.
    4. Assemble qi4j application by implementing #assemble method.
    5. Sets the identity of bean factory service. This identity is the spring bean name.
    6. Declare qi4j bootstrap in spring xml application context.

To bootstrap the Zest™ runtime in Spring, you should have a bootstrap bean that extends the
+org.qi4j.library.spring.bootstrap.Qi4jApplicationBootstrap+ and implement the
+org.springframework.context.ApplicationContextAware+.

A new bean will appear in the application context, called +"qi4jApplication"+ which is only
intended for internal use of this library.

Example application context;
[source,xml]
----
 <?xml version="1.0" encoding="UTF-8"?>

 <beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:qi4j="http://www.qi4j.org/schema/qi4j/spring"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  http://www.qi4j.org/schema/qi4j/spring http://www.qi4j.org/schema/qi4j/spring/spring-0.5.xsd">

  <!-- class that implements Qi4jApplicationBootstrap -->

  <qi4j:bootstrap class="org.hedhman.niclas.MyZestBootstrapper"/>

  <bean id="someService" class="org.hedhman.niclas.SomeService">

  <constructor-arg ref="someService"/> <!-- Reference qi4j comment service -->

 </bean>
----

[snippet,java]
----
source=libraries/spring/src/test/java/org/qi4j/library/spring/MyZestBootstrapper.java
tag=code
----
