Creates a dynamic proxy of the ColdFusion component that is passed to a Java library. Dynamic proxy lets you pass ColdFusion components to Java objects. Java objects can work with the ColdFusion components seamlessly as if they are native Java objects.


Metadata structure related to the current session.


ColdFusion (2018 release): Renamed the following parameters:

  • fullyQualifiedNameOfCFC  to cfc
  • interfaceName to interfaces


Other functions

Function syntax

createDynamicProxy(cfc, [interfaces])





Fully qualified name of the ColdFusion component or a CFC instance.


An array of Java interfaces for which you want to create the dynamic proxy.


The following example shows how to create a Java interface. Interface defines a method. A ColdFusion component implements the method as a ColdFusion function. The dynamic proxy of the ColdFusion component calls a Java class by passing the object of the interface. It then calls the method in ColdFusion as if it is a native Java class.

  1. Create a Java interface, MyInterface.

    public interface MyInterface 
    public String sayHello(); 
  2. Compile the Java file and place it in a directory, lib.

  3. Create a Java class, InvokeHelloProxy, that calls the ColdFusion object using the instance of the interface.The constructor, InvokeHelloProxy, creates an object of MyInterface. The invokeHello() method calls the sayHello()method using the object.

    public class InvokeHelloProxy 
    private MyInterface myInterface; 
    public InvokeHelloProxy(MyInterface x) 
    this.myInterface = x; 
    public String invokeHello() 
    return myInterface.sayHello(); 
  4. Compile the Java file and place it in a directory, lib.

  5. Create a CFC file, HelloWorld.cfc, that implements the method defined in the interface and save it in a directory, cfc.

    <cffunction name="sayHello" returntype="string"> 
    <cfreturn "Hello World!!!!"> 
  6. Add the following code in the Application.cfc.{{}}

    <cfset THIS.javaSettings = {LoadPaths = ["/lib"],reloadOnChange=true,watchInterval=10}/>
  7. Add a CFM file that creates a dynamic proxy for HelloWorld as interface, MyInterface. Create an object of InvokeHelloProxy class and initiate the class.The code creates a dynamic proxy of MyInterface.

    <cfset dynInstnace = createDynamicProxy("HelloWorld.cfc", ["MyInterface"])>  
    <cfset x = createObject("java","InvokeHelloProxy").init(dynInstnace)>  
    <cfset y = x.invokeHello()>  

    Example: using a CFC instance

    <cfset instance=new helloWorld()>  
    <cfset dynInstnace = createDynamicProxy(instance, ["MyInterface"])>  
    <cfset x = createObject("java","InvokeHelloProxy").init(dynInstnace)>  
    <cfset y = x.invokeHello()>  
  8. Deploy the application and access the CFM file.

Adobe logo

Sign in to your account