Coldfusion RESTful webservice:对象不是声明类的实例 [英] Coldfusion RESTful webservice: Object is not an instance of declaring class
问题描述
当我调用URL http://192.168.2.26:8080/rest/RestSample/season/1.json
时出现错误:
错误,ajp-bio-8012-exec-4,03/01/13,16:51:58 RestSample,对象不是声明类的实例包含或处理的文件的特定顺序是:C:\path_to\api\service.cfc''
这是 /api/service.cfc
文件:
< cfscript>
组件restpath =seasonrest =true
{
远程查询函数getSeasonsByUserId(numeric userid restargsource =Path)httpmethod =GETrestpath ={ userid}
{
var response =;
var qry = new Query();
var userQry =;
qry.setSQl(select * from mytable where userID =:userid);
qry.addParam(name =userid,value =#arguments.userid#,cfsqltype =cf_sql_numeric);
userQry = qry.execute()。getResult();
if(userQry.recordcount == 0)
{
response = userQry;
} else {
throw(type =Restsample.SeasonsNotFoundError,errorCode ='404',detail ='Seasons not found');
}
返回响应;
}
}
< / cfscript>
编辑#1 :本教程后:
http://www.anujgakhar.com/2012/ 02/20 / use-rest-services-in-coldfusion-10 /
编辑#2 :my application.cfc
< cfscript>
component output =false
{
this.name =RestSample;
this.applicationTimeout = createTimespan(0,0,0,0);
this.datasource =mydsn;
this.username =;
this.password =;
//this.restsettings.skipCFCWithError = true;
public boolean function onRequestStart()
{
restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()),this.name);
return true;
}
}
< / cfscript>
还要注意,在管理中刷新REST服务ALWAYS给我以下消息: p>
无法刷新REST服务。
无法初始化应用程序RestSample。
原因:应用程序不包含任何已启用的CFC。
应用程序不包含任何已启用的CFC。但是,我可以删除它们,并通过onRequestStart()添加它们,没有任何问题。 >
编辑#3
我目前的结构
/api/main/service.cfc
/api/application.cfc
/api/index.cfm
应用程式。 cfc
< cfscript>
component output =false
{
this.name =RestSample;
this.applicationTimeout = createTimespan(0,0,0,0);
this.datasource =mydsn;
this.username =;
this.password =;
this.restsettings.skipCFCWithError = true;
public boolean function onRequestStart()
{
restInitApplication(getDirectoryFromPath(getCurrentTemplatePath())。concat(main\,this.name);
return true;
}
}
< / cfscript>
service.cfc
< cfscript>
component restpath =seasonrest =true
{
remote query function getSeasonsByUserId(numeric userid restargsource =Path)httpmethod =GETrestpath ={ userid}
{
var response =;
var qry = new Query();
var userQry =;
qry.setSQl(select * from mytable where userID =:userid);
qry.addParam(name =userid,value =#arguments.userid#,cfsqltype =cf_sql_numeric);
userQry = qry.execute()。getResult();
return userQry;
}
}
< / cfscript>
我仍然得到以下错误:
'对象不是声明类
的实例
解决方案我创建了 C:\ColdFusion10\cfusion\root
(而不是站点的IIS根目录)通过管理控制台的REST服务没有任何问题。
When I call the URL http://192.168.2.26:8080/rest/RestSample/season/1.json
I get the error:
"Error","ajp-bio-8012-exec-4","03/01/13","16:51:58","RestSample","object is not an instance of declaring class The specific sequence of files included or processed is: C:\path_to\api\service.cfc'' "
This is the /api/service.cfc
file:
<cfscript>
component restpath="season" rest="true"
{
remote query function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}"
{
var response = "";
var qry = new Query();
var userQry = "";
qry.setSQl("select * from mytable where userID = :userid");
qry.addParam(name="userid", value="#arguments.userid#", cfsqltype="cf_sql_numeric");
userQry = qry.execute().getResult();
if(userQry.recordcount == 0)
{
response = userQry;
} else {
throw(type="Restsample.SeasonsNotFoundError", errorCode='404', detail='Seasons not found');
}
return response;
}
}
</cfscript>
Edit #1: following this tutorial:
http://www.anujgakhar.com/2012/02/20/using-rest-services-in-coldfusion-10/
Edit #2: my application.cfc
<cfscript>
component output="false"
{
this.name = "RestSample";
this.applicationTimeout = createTimespan(0,0,0,0);
this.datasource = "mydsn";
this.username = "";
this.password = "";
//this.restsettings.skipCFCWithError = true;
public boolean function onRequestStart()
{
restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), this.name);
return true;
}
}
</cfscript>
Also would like to note, refreshing REST services in the admin ALWAYS gives me the following message:
Unable to refresh REST service.
Application RestSample could not be initialized.
Reason: The application does not contain any rest enabled CFCs.
The application does not contain any rest enabled CFCs.
However, I can remove them and add them via the onRequestStart() without any problems.
Edit #3
My current structure
/api/main/service.cfc
/api/application.cfc
/api/index.cfm
application.cfc
<cfscript>
component output="false"
{
this.name = "RestSample";
this.applicationTimeout = createTimespan(0,0,0,0);
this.datasource = "mydsn";
this.username = "";
this.password = "";
this.restsettings.skipCFCWithError = true;
public boolean function onRequestStart()
{
restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()).concat("main\"), this.name);
return true;
}
}
</cfscript>
service.cfc
<cfscript>
component restpath="season" rest="true"
{
remote Query function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}"
{
var response = "";
var qry = new Query();
var userQry = "";
qry.setSQl("select * from mytable where userID = :userid");
qry.addParam(name="userid", value="#arguments.userid#", cfsqltype="cf_sql_numeric");
userQry = qry.execute().getResult();
return userQry;
}
}
</cfscript>
I still get the following error:
'object is not an instance of declaring class
解决方案 I created the files under C:\ColdFusion10\cfusion\wwwroot
(instead of the site's IIS root) and was able to register the REST service via the administration console without any issue.
这篇关于Coldfusion RESTful webservice:对象不是声明类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!