下面是我在 JAXB 解组过程中使用的 JAXB 绑定类。
package com;
@XmlRootElement(name = "request")
@XmlAccessorType(XmlAccessType.FIELD)
public class CustAcct {
@XmlAttribute
private String cust;
@XmlAttribute
private String acct;
public CustAcct() {
super();
}
public String getCust() {
return cust;
}
public void setCust(String s) {
cust = s;
}
public String getAcct() {
return acct;
}
public void setAcct(String s) {
acct = s;
}
}
现在我的问题是,我无法在上面的类中包含注释@Context ServletContext。
public class CustAcct {
@XmlAttribute
private String cust;
@XmlAttribute
private String acct;
@Context
ServletContext cont ;
我收到 Exception ,带有此消息
javax.servlet.servletcontext is an interface and jaxb can't handle interfaces
请让我知道是否可以在 JAXB 绑定类中使用内置的 ServletContext 注释?
提前致谢 。
我试过这样,
@XmlRootElement(name = "request")
@XmlAccessorType(XmlAccessType.FIELD)
public class CustAcct {
@XmlAttribute
private String acct;
@XmlTransient
@Context
ServletContext con;
public CustAcct() {
super();
}
public String getAcct() {
return acct;
}
public void setAcct(String s) {
acct = s;
}
}
但是当我尝试在 Jersey 服务中访问它时出现以下异常
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException