2
下面是我在JAXB Unmarshalling過程中使用的JAXB綁定類。現在是否可以在JAXB綁定類中內置ServletContext註釋?
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 ;
我得到的例外,與此消息
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;
}
}
但我正在逐漸當我試圖訪問它澤西島Service中
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
容器不能注入'ServletConext'到域對象。如果您必須在ServletContext的域對象上做任何事情,您必須在Servlet的方法或JAX-RS資源的方法中執行此操作。 – 2012-08-10 14:49:28