我得到异常com.sun.jersey.api.container.ContainerException:当我运行我的简单应用程序,使用带有泽西的Restfull Web服务打印XML格式的消息 web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e194 -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.irfan.javadev.messenger</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webresources/*</url-pattern>
</servlet-mapping>
</web-app>
ServiceLayer: MessageService .java
public class MessageService {
private Map<Long, Message> messages = DataBaseClass.getMessages();
public List<Message> getAllMessages() {
return new ArrayList<Message>(messages.values());
}
}
DemoDataBase类: DataBaseClass.java
public class DataBaseClass {
private static Map<Long, Message> messages = new HashMap<Long, Message>();
private static Map<Long, Profile> profiles = new HashMap<Long, Profile>();
public static Map<Long, Message> getMessages() {
return messages;
}
public static Map<Long, Profile> getProfiles() {
return profiles;
}
}
消息实体类:Message.java
@XmlRootElement
public class Message {
private long id;
private String message;
private Date created;
private String author;
public Message() {
super();
}
public Message(long id, String message, String author) {
super();
this.id = id;
this.message = message;
this.author = author;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
资源类: MessageResource.java
@Path("/messages")
public class MessageResource {
MessageService msgService = new MessageService();
@GET
@Produces(MediaType.APPLICATION_XML)
public List<Message> getMessage() {
return msgService.getAllMessages();
}
}
这个异常背后的原因是什么? 提前谢谢:)