我有一个bean,它从org.springframework.security.core.userdetails.User扩展,并使用这个bean和openID。豆看起来像:
package com.employee;
import java.util.Collection;
import javax.xml.bind.annotation.XmlRootElement;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
@XmlRootElement(name="Employee")
public class Employee extends User{
private int empId;
private String deptName;
public Employee() {
super("", "unused", null);
}
public Employee(String username, Collection<GrantedAuthority> authorities) {
super(username, "unused", authorities);
}
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
}
控制器接受Employee的实例:
@RequestMapping(value =“/ addEmp.do”, method = RequestMethod.POST) public @ResponseBody String addEmployee(@RequestBody Employee emp){...}
我已向以下正文发送了一个POST请求:
<?xml version="1.0" encoding="UTF-8"?>
<Employee>
<empId>10</empId>
<deptName>abc</deptName>
</Employee>
但是在调用addEmp操作时得到以下JAXB异常:
2012-12-16 15:25:55,364{HH:mm:ss} DEBUG [http-bio-8080-exec-1] (AbstractHandlerExceptionResolver.java:132) -
Resolving exception from handler [public java.lang.String com.main.EmpController.addEmployee(com .employee.Employee)]:
org.springframework.http.converter.HttpMessageNotReadableException: Could not unmarshal to
[class com.employee.Employee]: Unable to create an instance of com.employee.Employee; nested exception is
javax.xml.bind.UnmarshalException: Unable to create an instance of com.employee.Employee
答案 0 :(得分:1)
错误消息:
无法创建com.employee
的实例
可能意味着输入不提供有效的员工属性。在构造函数
中public Employee() {
super("", "unused", null);
}
默认用户名设置为'',但spring security不接受空白用户名。