Skip to content

ColdFusion Spring Integration

markmandel edited this page Feb 16, 2012 · 3 revisions

ColdFusion Spring integration is Spring Custom Schema, that leverages Spring's dynamic scripting support and heavily, and uses many of its same configuration elements.

Note: This has been tested with Spring 2.5

Requirements

  • ColdFusion 8 or 9
  • Java 1.5+
  • Including the following .jar's with the JavaLoader loadpaths:
  • /javaloader/support/cfcdynamicproxy/lib/cfcdynamicproxy.jar
  • /javaloader/support/spring/lib/spring-coldfusion.jar
  • spring.jar (from Spring download)
  • cglib-nodep-2.1_3.jar (from Spring download)
  • loadColdFusionClassPath must be true

Java Build Path Requirements

If you are using the Spring Integration within a Java Project, the following libraries will need to be added to your Build Path so that it can compile:
/<coldfusion-home>/lib/cfusion.jar
/<coldfusion-home>/runtime/lib/jrun.jar

API Documentation

JavaDoc Documentation

Reference

This custom Spring schema enables you to create ColdFusion Components in Spring that are wrapped in the ColdFusion Component Dynamic Proxy that is also shipped with JavaLoader. Therefore, when Spring encounters these Objects it treats them as if they were native Java objects, implementing a given set of Java Interfaces.

Initialising Spring

Starting up Spring with JavaLoader requires some bootstrapping as we are using a custom ClassLoader, for example:

spring = javaloader.create("org.springframework.context.support.FileSystemXmlApplicationContext").init();

//we tell Spring to use JavaLoader's URLClassLoader for getting any Java Classes
spring.setClassLoader(javaloader.getURLClassLoader());

//tell Spring where our XML file is
spring.setConfigLocation("file://" & expandPath("./spring.xml"));

//lets load up our Spring.xml file.
spring.refresh();

This loads up Spring for us within JavaLoader.

Configuring the JavaLoader Spring-ColdFusion Schema

To add the JavaLoader Spring-ColdFusion schema to your Spring.xml file, add the following:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:coldfusion="http://www.compoundtheory.com/javaloader/schema/coldfusion"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.compoundtheory.com/javaloader/schema/coldfusion http://www.compoundtheory.com/javaloader/schema/spring-coldfusion.xsd"
    >
...
</beans>

This will give you access to the coldfusion: namespace in your XML configuration file. Defining a ColdFusion Component in Spring

To define a ColdFusion Component in Spring:

<coldfusion:cfc id="message"
        script-source="file:///model/Message.cfc" 
        script-source-relative="true"
        script-interfaces="com.IMessage"
        />

Attribute: id

The id of the defined Bean.

Attribute: script-source

The path to the CFC that is to be instantiated by this been definition.

Attribute: script-source-relative

An optional attribute, that defines if the script-source attribute is relative to the page context (true), or an absolute path (false). By default, this is set to 'true'.

Attribute: script-interfaces

A comma delimited list of Java interfaces that the dynamic proxy will implement, and the methods the ColdFusion component will also implement.

There are several more optional attributes and child elements available that follow Spring definition guidelines. Downsides to using Spring to define your ColdFusion Components

There are two downsides to defining your ColdFusion Components within Spring that you should be aware of:

  1. There is a slight performance penalty for invoking ColdFusion Components through a dynamic proxy. Since most of the CFCs defined in Spring will be singletons this performance hit should be negligible.
  2. You can no longer user onMissingMethod with ColdFusion Components, as they are defining a Java Interface, and only those methods can be called by either other Java Objects or ColdFusion code.

Clone this wiki locally