• Spring 中出现Element : property Bean definitions can have zero or more properties. Property elements correspond to JavaBean setter methods exposed by the bean classes. Spring supports primitives, refer


    在这个ApplicationContext.xml文件中出现 如下报错

    Element : property

    Bean definitions can have zero or more properties. Property elements correspond to JavaBean setter 

     methods exposed by the bean classes. Spring supports primitives, references to other beans in the same or 

     related factories, lists, maps and properties.

    Content Model : (description?, (meta | bean | ref | idref | value | null | array | list | set | map | props | 

     namespace:uri="##other")?)

    或者

    Multiple annotations found at this line:

    - No constructor with 0 arguments defined in class 

    'cn.lonecloud.bean.step08iocfieldbyProperty.UserBean'

    请在自己导入的实体bean中检查是否没有加无参数的构造函数

    package cn.lonecloud.bean.step08iocfieldbyProperty;
    
    public class UserBean {
    
        private String userName;
        
        private int age;
        
        private String address;
    
        public String getUserName() {
            return userName;
        }
    
        public void setUserName(String userName) {
            this.userName = userName;
        }
    
        public int getAge() {
            return age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    
        public String getAddress() {
            return address;
        }
    
        public void setAddress(String address) {
            this.address = address;
        }
        
        @Override
        public String toString() {
            return "UserBean [userName=" + userName + ", age=" + age + ", address="
                    + address + "]";
        }
        //如果在这个实体bean中设置了这个带构造函数的构造方法则需要在这里加一个无参数的构造函数
        public UserBean(){
            
        }
        public UserBean(String userName, int age, String address) {
            super();
            this.userName = userName;
            this.age = age;
            this.address = address;
        }
    }
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    		<bean id="userBean" class="cn.lonecloud.bean.step08iocfieldbyProperty.UserBean" >
    		<property name="userName" value="lonecloud"></property>
    		<property name="age" value="10"></property>
    		<property name="address" value="nanchang"></property>
    	</bean>
    
    </beans>
    
  • 相关阅读:
    【扯淡篇】SDOI2018丶一轮游丶记
    初来乍到, 多多包涵~
    【学术篇】The Xuanku Inversion Magic学习笔记
    【模板篇】树状数组(六)
    【学术篇】CF932E Team Work && bzoj5093 图的价值
    【模板篇】NTT和三模数NTT
    【学术篇】CF833B TheBakery 分治dp+主席树
    【学术篇】NOI2015 品酒大会 后缀数组+并查集
    【模板篇】数论大杂烩~
    【学术篇】SPOJ GEN Text Generator AC自动机+矩阵快速幂
  • 原文地址:https://www.cnblogs.com/lonecloud/p/5743557.html
Copyright © 2020-2023  润新知