Solve the "Could not find the ColdFusion Component" issue

April 24, 2008

I'm sure someone has posted this before but for my own reference (or anyone who doesn't know)!

If you want to be able to create a CFC from a template that needs you to navigate up the directory tree then you can't because of the dot notation that ColdFusion uses. You'll probably see an error like


Could not find the ColdFusion Component or Interface path.to.cfc.
Ensure that the name is correct and that the component or interface exists.

Or


The ../path.to.cfc name is not a valid component or interface name.
Component and interface names cannot be empty and cannot start or end with a period.

The way to solve this is to create your own function in Application.cfc which will look something like this:


<cffunction name="CreateCFC" returntype="any">
<cfargument name="path" required="true" />

<cfscript>
Return CreateObject('component', Arguments.path);
</cfscript>
    
</cffunction>

So, now all you need to do when you want to create a CFC, instead of doing:


CreateObject('component', 'path.to.my.cfc');

You can do this from anywhere inside your web application (by which I mean anywhere at the same level or below your Application.cfc):


CreateCFC('path.to.my.cfc');

A simple solution to an annoying problem!


3 comments

  1. I give the path from the root of the application in my create object statements. Since the path is from the root of the application, I don't need to worry about walking up a directory tree.

    You've essentially made an application scoped factory. In and of itself, this isn't a bad thing. If you are going to write CFC based applications of complexity, it might be a good idea to look into ColdSpring or LightWire.

    Both are factories and also provide Dependancy Injection capabilities which are very helpful in keeping your code clean and your dependancies in line.

    Hope this helps.

    DW

    Comment by Dan Wilson – April 24, 2008
  2. Thanks. It helped me to solve the problem.

    Comment by Arun – August 07, 2009
  3. If you do any Flex development that has remote object calls to CFC methods, you will see this error if you don't configure the path to your CF server's services.config.xml file. The error will show up in the application.log file (viewable in the CFAdmin)

    I usually just add add the path into the compiler arguments when I start a new Flex project. Sometimes however, I end up needing to re-creating my Flex project instance and I often forget to add the config setting back until I see the error. Just thought I would bring this up.

    Project -> Properties -> Flex Compiler -> Additional Compiler Arguments:
    -locale en_US -services "C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\flex\services-config.xml"

    Comment by molaro – January 25, 2010

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.