Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JAX-RS@PUT注释未被继承_Java_Jakarta Ee_Annotations_Jax Rs - Fatal编程技术网

Java JAX-RS@PUT注释未被继承

Java JAX-RS@PUT注释未被继承,java,jakarta-ee,annotations,jax-rs,Java,Jakarta Ee,Annotations,Jax Rs,我有一个抽象类,它声明了一个@PUT方法: public abstract class BaseResource<T> { @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public abstract Response create(T entityClass); } 公共抽象类BaseResource{ @放 @使用(MediaType.APPL

我有一个抽象类,它声明了一个
@PUT
方法:

public abstract class BaseResource<T> {

  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public abstract Response create(T entityClass);

}
公共抽象类BaseResource{
@放
@使用(MediaType.APPLICATION_JSON)
@产生(MediaType.APPLICATION_JSON)
公共抽象响应创建(T entityClass);
}
然后一个类实现该方法:

public class GroupsResource extends BaseResource<Group> {

  @Override
  public Response create(Group newGroup) {

    // this works.
    // ...
    return response.build();

  }
}
公共类组资源扩展了BaseResource{
@凌驾
公共响应创建(组新建组){
//这很有效。
// ...
返回response.build();
}
}
与GET方法类似的代码也可以工作,但此代码被拒绝,因为不允许使用405方法。但是如果我用
@PUT
注释实现,它确实可以工作。因此,抽象声明上的@PUT注释似乎没有被继承

有什么想法吗

更新:


我从零开始使用Java EE7,效果非常好。

我在项目中遇到了同样的问题,我这样解决了它:

//Inject the object mapper because you don't want to retreive an "Object"
@Inject
ObjectMapper objectMapper;

@PUT
//The PUT endpoint retrieves a plain object
public Response update(Object object){
   //Now we determine the concrete type of the object by using reflection
   ParameterizedType p = (ParameterizedType) getClass().getGenericSuperclass();
   Class<DTO> clazz = (Class<DTO>) p.getActualTypeArguments()[0];

   //Pass the object and the determined type to the objectmapper
   DTO dto = objectMapper.convertValue(object, clazz);

   //Now call an abstract method that deals with the object in you concrete class
   updateDto(dto);
}

protected abstract Response updateDto(DTO dto);
//插入对象映射器,因为您不想检索“对象”
@注入
对象映射器对象映射器;
@放
//PUT端点检索普通对象
公共响应更新(对象){
//现在我们使用反射来确定对象的具体类型
ParameteredType p=(ParameteredType)getClass().getGenericSuperclass();
类clazz=(类)p.getActualTypeArguments()[0];
//将对象和确定的类型传递给objectmapper
DTO DTO=objectMapper.convertValue(对象,clazz);
//现在调用一个抽象方法来处理具体类中的对象
更新到(dto);
}
受保护的抽象响应更新到(DTO DTO);

我刚刚发现了一个看起来很熟悉的bug报告,但虽然它是关闭的,但它看起来并不像是固定的:在我看来,如果使用抽象类,会增加复杂性。嗯,有点。我喜欢抽象。连贯性也是可取的。通过在抽象类上添加方法声明,我知道即使不读取也可以扩展抽象类的类的行为。