本帖最后由 pf711 于 2014-03-11 21:41:46 编辑

解决方案 »

  1.   

    楼主的在javabean上的jaxb注解有问题。只要对javabean的jaxb注解修改即可//Beans
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.NONE)
    public class Beans {
    @XmlElementRef//用这个注解会连接到Bean类上
    private List<Bean> beans; public List<Bean> getBeans() {
    return beans;
    } public void setBeans(List<Bean> beans) {
    this.beans = beans;
    }
    }
    //Bean
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.NONE)
    public class Bean {
    @XmlAttribute
    private String id;
    @XmlAttribute
    private String classname;
    @XmlElementRef//用这个注解会连接到Property类上
    private List<Property> properties;

    public String getId() {
    return id;
    }
    public void setId(String id) {
    this.id = id;
    }
    public String getClassname() {
    return classname;
    }
    public void setClassname(String classname) {
    this.classname = classname;
    }
    public List<Property> getProperties() {
    return properties;
    }
    public void setProperties(List<Property> properties) {
    this.properties = properties;
    }
    }
    //Property
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.NONE)
    public class Property {
    @XmlAttribute
    private String name;
    @XmlAttribute
    private String reference;

    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getReference() {
    return reference;
    }
    public void setReference(String reference) {
    this.reference = reference;
    }
    }//测试代码                JAXBContext context=JAXBContext.newInstance(Beans.class);
    Unmarshaller unmarshaller=context.createUnmarshaller();
    Beans beans=(Beans) unmarshaller.unmarshal(new File("楼主的xml文件"));
    List<Bean> list=beans.getBeans();
    for(Bean bean:list){
    System.out.println(bean.getId()+":"+bean.getClassname());
    List<Property> properties=bean.getProperties();
    if(properties!=null){
    for(Property property : properties){
    System.out.println(property.getName()+":"+property.getReference());
    }
    }
    }
      

  2.   

    第一眼看见代码是,我觉得你的impl中的l是不是写成1了...
      

  3.   

    通常注解写在get方法或属性上或属性上,set上倒是第一次听说