简体   繁体   English

为“MediaType.APPLICATION_JSON”生成的注释类型的属性值未定义

[英]The attribute value is undefined for the annotation type Produces for “MediaType.APPLICATION_JSON”

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") 我得到一个奇怪的警告(在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;
}
}

Also maven builds the jar file without problems. maven也可以毫无问题地构建jar文件。 But I get an error from the OSGI container, telling me the jar is failed. 但我收到OSGI容器的错误,告诉我jar失败了。

Use @javax.ws.rs.Produces instead of javax.enterprise.inject.Produces 使用@javax.ws.rs.Produces而不是javax.enterprise.inject.Produces

import javax.ws.rs.Produces; 
// import javax.enterprise.inject.Produces;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 @Produces(MediaType.APPLICATION_JSON) 和 @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) 参数类型的内部详细信息? - Internal details for @Produces(MediaType.APPLICATION_JSON) and @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) argument types? @Consumes(MediaType.APPLICATION_JSON) 注释但将请求正文作为字符串获取 - @Consumes(MediaType.APPLICATION_JSON) annotation but getting request body as string MediaType.APPLICATION_JSON返回类型给出500内部错误 - MediaType.APPLICATION_JSON return type gives 500 Internal error Grizzly在MediaType.Application_JSON上失败 - Grizzly fails on MediaType.Application_JSON Jersey REST客户端 - 将自定义MediaType视为MediaType.APPLICATION_JSON - Jersey REST Client - Treat Custom MediaType as MediaType.APPLICATION_JSON “ MediaType.APPLICATION_JSON”和“ application / json”之间有什么区别 - What is the difference betweeen “MediaType.APPLICATION_JSON” and “application/json” MediaType.APPLICATION_JSON和MediaType.APPLICATION_XML异常,但MediaType.TEXT_XML运行正常 - Exception with MediaType.APPLICATION_JSON and MediaType.APPLICATION_XML but MediaType.TEXT_XML running fine 在 RESTful Web 服务中使用 @Consumes(MediaType.APPLICATION_JSON) 的问题 - Problems using @Consumes(MediaType.APPLICATION_JSON) in RESTful web service Jersey演示应用程序中的MediaType.APPLICATION_XML和MediaType.APPLICATION_JSON - MediaType.APPLICATION_XML and MediaType.APPLICATION_JSON in a Jersey demo application Jersy Rest服务接受MediaType.APPLICATION_JSON的java.util.Map - Jersy Rest service to accept java.util.Map for MediaType.APPLICATION_JSON
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM