5

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
4

2 に答える 2

3

もう少し簡単な例から始めて、動作状態に到達できるかどうかを確認しましょう。次の手順に従って、動作するRESTサービスを正常にセットアップしました。

ColdFusionAdministratorのRESTServicesに移動し、既存のREST登録をすべて削除します。

Webルートの新しいディレクトリに、次のコンテンツを含むApplication.cfcを作成します(<cfscript>CF 9以降を使用している場合は、タグは必要ありません)。

component output="false"
{
    this.name = "RestSample";
}

同じディレクトリに、次の内容でindex.cfmを作成します。

<cfset restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), "RestSample") />
Done.

同じディレクトリに、次の内容でservice.cfcを作成します。

component restpath="season" rest="true"
{
    remote struct function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}"
    {
        return {
            'hello': 'world'    
        };
    } 
}

まず、ブラウザからindex.cfmを参照し、「完了」というテキストが表示されることを確認します。

ColdFusionAdministratorでRESTサービスを開き、RESTサービスが正常に登録されていることを確認します。

最後に、/ rest / RestSample / season / 123を介してブラウザーでRESTリソースを参照すると、信頼できる「helloworld」が表示されることを願っています。

それでも問題が解決しない場合はお知らせください。何がで​​きるかを確認します。

于 2013-03-02T00:04:56.180 に答える
1

(サイトのIISルートの代わりに)ファイルを作成しC:\ColdFusion10\cfusion\wwwroot、管理コンソールを介して問題なくRESTサービスを登録できました。

于 2013-03-28T15:14:35.883 に答える