"MediaType.APPLICATION_JSON" 的注释类型 Produces 的属性值未定义
The attribute value is undefined for the annotation type Produces for "MediaType.APPLICATION_JSON"
对于这个非常简单的 restful 服务代码,我收到一个奇怪的警告(同时在 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<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;
}
}
maven 构建 jar 文件也没有问题。但是我从 OSGI 容器中得到一个错误,告诉我 jar 失败了。
使用@javax.ws.rs.Produces
代替javax.enterprise.inject.Produces
import javax.ws.rs.Produces;
// import javax.enterprise.inject.Produces;
对于这个非常简单的 restful 服务代码,我收到一个奇怪的警告(同时在 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<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;
}
}
maven 构建 jar 文件也没有问题。但是我从 OSGI 容器中得到一个错误,告诉我 jar 失败了。
使用@javax.ws.rs.Produces
代替javax.enterprise.inject.Produces
import javax.ws.rs.Produces;
// import javax.enterprise.inject.Produces;