I am getting a weird warning (while hovering the red line in eclipse) for this very simple restful service code: (Eclipse draws a red line under "MediaType.APPLICATION_JSON")
import java.util.List;
import java.util.logging.Logger;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import com.myCompany.annotation.RestfulServiceAddress;
import com.myCompany.myProject.middleware.api.myService;
@RestfulServiceAddress("/myCompany-middleware")
public class myServiceImpl implements myService {
private EntityManagerFactory entityManagerFactory;
@GET
@Path("/getStuff")
@Produces(MediaType.APPLICATION_JSON)
public List<Object> getStuff() {
EntityManager entityManager = entityManagerFactory
.createEntityManager();
try {
return entityManager.createQuery(
"Select S from Stuff S", Object.class)
.getResultList();
} catch (Exception ex) {
ex.printStackTrace();
return null;
} finally {
entityManager.close();
}
}
public EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
public void setEntityManagerFactory(
EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
}
Also maven builds the jar file without problems. But I get an error from the OSGI container, telling me the jar is failed.
Use @javax.ws.rs.Produces
instead of javax.enterprise.inject.Produces
import javax.ws.rs.Produces;
// import javax.enterprise.inject.Produces;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With