Tek*_*kus 5 rest coldfusion web-services cfml
当我调用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>
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>
Run Code Online (Sandbox Code Playgroud)
编辑#1:遵循本教程:http: //www.anujgakhar.com/2012/02/20/using-rest-services-in-coldfusion-10/
编辑#2:我的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>
Run Code Online (Sandbox Code Playgroud)
还要注意,在管理员中刷新REST服务总是给我以下消息:
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.
Run Code Online (Sandbox Code Playgroud)
但是,我可以删除它们并通过onRequestStart()添加它们没有任何问题.
编辑#3
我目前的结构
/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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我仍然收到以下错误:
'object is not an instance of declaring class
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2239 次 |
| 最近记录: |