-
Notifications
You must be signed in to change notification settings - Fork 25
ColdFusion Spring Integration
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
- 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
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
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.
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.
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"
/>The id of the defined Bean.
The path to the CFC that is to be instantiated by this been definition.
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'.
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:
- 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.
- 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.