Jersey を使用する MiddleTierResources.java という名前の Jersey リソース クラスがあります (次の関連インポートがあります: javax.ws.rs.*; javax.ws.rs.core.MediaType; javax.ws.rs.core.Response;)。
そしてそのクラスでは、メソッドは次のように注釈が付けられています。
@GET
@Path("/users/{userid}")
@Produces({MediaType.APPLICATION_JSON})
public Response getUserById (final @PathParam("userid") String userid) {
Base.open("org.postgresql.Driver", "jdbc:postgresql:app", "user", "pass");
User user = User.findById(Integer.parseInt(userid));
Base.close();
return Response.ok(user).build();
}
モデル クラスをビルドして計測し、ビルドしたサーバーを起動した後、localhost:9090/users/1 に移動すると、次のエラーが表示されます。
org.javalite.activejdbc.DBException: failed to determine Model class name,
are you sure models have been instrumented?
しかし、奇妙なことに、このクラス自体を単純に起動すると、次の Main メソッドが実行され、問題なく実行されます。
public static void main(String[] args){
Base.open("org.postgresql.Driver", "jdbc:postgresql:app", "user", "pass");
User user = User.findById(1);
Base.close();
System.out.println("MAIN SAYS: "+user);
}
そして正常に印刷されます:
MAIN SAYS: Model: com.myproject.application.models.User, table: 'users',
attributes: {wallet_secret=null, id=1, username=Johnny, phone=null,
updated_at=2014-07-16 16:57:30.901, email=null, wallet_address=null,
created_at=2014-07-16 16:57:30.901, password=1234567890, activation=null,
account_type=null}
だから、私は本当に何が起こっているのか理解できませんか?main メソッドは正常に動作するのに、同じクラスでサーバーとして実行し、そのメソッドを使用すると動作しないのはなぜですか? クラスに他のアノテーションがある場合、インストルメンテーションは機能しませんか?
助けてくれてどうもありがとう!:)