forked from markmandel/JavaLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.cfm
More file actions
70 lines (59 loc) · 2.61 KB
/
Copy pathindex.cfm
File metadata and controls
70 lines (59 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<html>
<head><title>JavaLoader Spring Example</title></head>
<style type="text/css">
body {
font-family: Verdana, Helvetica, san-serif;
font-size: small;
}
</style>
<body>
<p>
In this example we will be using the Spring integration that enables us to use ColdFusion components inside Spring.
</p>
<p>
Some bootstrap code will be neccessary to make Spring work in this environment.
</p>
<p>
We will also being using the dynamic compilation power of JavaLoader to provide the Java objects that Spring is going to utilise
</p>
<p>
We will create a Java Object called <a href="src/com/MessageReceiver.java">MessageReciever</a>, which will take a CFC named 'Message',
which has a method called 'getMessage()', which the Java object will call.
</p>
<cfscript>
libpaths = [];
//MUST have Spring in our classpath
ArrayAppend(libpaths, expandPath("./lib/spring.jar"));
//MUST have the cglib library for run time proxying in Spring
ArrayAppend(libpaths, expandPath("./lib/cglib-nodep-2.1_3.jar"));
//MUST have the JavaLoader's ColdFusion Dynamic Proxy
ArrayAppend(libpaths, expandPath("/javaloader/support/cfcdynamicproxy/lib/cfcdynamicproxy.jar"));
//MUST include the JavaLoader's Spring Integration library
ArrayAppend(libpaths, expandPath("/javaloader/support/spring/lib/spring-coldfusion.jar"));
//this is the directory that stores all our Java source
srcpaths = [ expandPath("./src") ];
//We have to load the ColdFusion classpath as the ColdFusion dynamic proxy requires it.
loader = createObject("component", "javaloader.JavaLoader").init(loadPaths=libpaths, loadColdFusionClassPath=true, sourceDirectories=srcpaths);
//this is the path to our XML file. Note the 'file://' prefix, this is important to Spring
path = "file://" & expandPath("./spring.xml");
//Some windows users need to use this: path = "file:/" & expandPath("./spring.xml");
//The FileSystemXMLApplicationContext I find is the easiest way to load up Spring
spring = loader.create("org.springframework.context.support.FileSystemXmlApplicationContext").init();
/*
we HAVE to set the classloader from JavaLoader as the Spring ClassLoader, so Spring knows where
to create Java Object from.
*/
spring.setClassLoader(loader.getURLClassLoader());
spring.setConfigLocation(path);
spring.refresh();
//finally, after all that, let's grab our MessageReciever Java Object!
messageReceiver = spring.getBean("messageReceiver");
</cfscript>
<p>
Spring Says:
<cfoutput>
<strong>#messageReceiver.getMessage().getMessage()#</strong>
</cfoutput>
</p>
</body>
</html>