I am creating the plugin.
But I don't have access to BD from Resource files for Api.
I have table model (ModelServiceImpl.java)
@Scanned
@Named
public class ModelServiceImpl implements ModelService {
@ComponentImport
private final ActiveObjects ao;
@Inject
public ModelServiceImpl(ActiveObjects ao)
{
this.ao = checkNotNull(ao);
}
...
}
And Resource file for API(ModelResource.java):
@Path("/endpoint")
public class ModelResource {
private ModelService modelService;
public ModelResource(ModelService modelService) {
this.modelService = modelService;
}
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
public Response getModel(@QueryParam("id") int id) {
CacheControl cacheControl = new CacheControl();
cacheControl.setNoCache(true);
return Response.ok(getModelById(id)).cacheControl(cacheControl).build();
}
private Model getModelById(int id) {
return modelService.getById(id); //modelService is null (NullPointerException)
}
}
How can I access the database in the resource file?