URLを呼び出すと、http://192.168.2.26:8080/rest/RestSample/season/1.json
次のエラーが発生します。
"Error"、 "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>
編集#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>
また、管理者で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.
ただし、問題なく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>
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>
それでも次のエラーが発生します。
'object is not an instance of declaring class