I have a Jersey resource class called MiddleTierResources.java that uses Jersey (has the following related imports: javax.ws.rs.*; javax.ws.rs.core.MediaType; javax.ws.rs.core.Response;)
And in that class, methods are annotated like this:
@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();
}
After I build & instrument the model classes, and then fire up the built server, and when I go to localhost:9090/users/1, the following error shows up:
org.javalite.activejdbc.DBException: failed to determine Model class name,
are you sure models have been instrumented?
However, the strange thing is that when I simply fire up this class itself, it runs the following Main method and runs just fine!
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);
}
and successfully prints out:
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}
So I really don't understand what's happening? Why is it that the main method runs properly, but in the same class when I run it as a server and use its methods, it doesn't work? Does instrumentation not work when there are other annotations in the class?
Thanks a lot for you help! :)