对于这个非常简单的宁静服务代码,我得到一个奇怪的警告(在eclipse中悬停红线):
(Eclipse在“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 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;
}
}
maven也可以毫无问题地构建jar文件.但我收到OSGI容器的错误,告诉我jar失败了.