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>
时间: 2024-07-30 14:26:15

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的相关文章

Spring中AOP和IOC深入理解

spring框架 Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spring的用途不仅仅限于服务器端的开发.从简单性.可测试性和松耦合性的角度而言,绝大部分Java应用都可以从Spring中受益. ◆目的:解决企业应用开发的复杂性 ◆功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能 ◆范围:任何Java应用 Spring是一个轻量级控制反转(IoC)和面向切面(AOP)的容器框架. Spr

玩转Spring MVC(五)----在spring中整合log4j

在前边的基础上,本文主要总结一下如何在spring 中配置log4j,在本文末尾会给出完整项目的链接. 首先是web.xml中要新添加的代码: <!-- 6. 配置log4j --> <!--6.1 配置加载log4j.xml文件路径 --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/classes/spring

spring 中容器 map、set、list、property 的 bean 实例化

参考:http://www.kaifajie.cn/spring/9966.html <bean id="fieldMap" class="org.springframework.beans.factory.config.MapFactoryBean"> <property name="sourceMap"> <map> <entry key="title" value-ref=&qu

Spring Core Container 源码分析七:注册 Bean Definitions

前言 原本以为,Spring 通过解析 bean 的配置,生成并注册 bean defintions 的过程不太复杂,比较简单,不用单独开辟一篇博文来讲述:但是当在分析前面两个章节有关 @Autowired.@Component.@Service 注解的注入机制的时候,发现,如果没有对有关 bean defintions 的解析和注册机制彻底弄明白,则很难弄清楚 annotation 在 Spring 容器中的底层运行机制:所以,本篇博文作者将试图去弄清楚 Spring 容器内部是如何去解析 b

Spring中 bean定义的parent属性机制的实现分析

在XML中配置bean元素的时候,我们常常要用到parent属性,这个用起来很方便就可以让一个bean获得parent的所有属性 在spring中,这种机制是如何实现的?     对于这种情况 transactionProxy01的parent属性是transactionProxy1 此时我们要获取transactionProxy01的实例 spring应该如何处理呢? <bean id="transactionProxy01" parent="transactionP

使用反射创建Bean、Spring中是如何根据类名配置创建Bean实例、Java提供了Class类获取类别的字段和方法,包括构造方法

Java提供了Class类,可以通过编程方式获取类别的字段和方法,包括构造方法 获取Class类实例的方法: 类名.class 实例名.getClass() Class.forName(className) public class RefTest { @Test public void testRef(){ //Class cls = RefTest.class; //Class.forName("com.jboa.service.RefTest"); //new RefTest()

由一个RABBITMQ监听器死循环引出的SPRING中BEAN和MAPPER接口的注入问题

1 @Slf4j 2 @RestController 3 @Component 4 public class VouchersReceiverController implements MessageListener { 5 6 @Autowired 7 private VouchersService vouchersService; 8 9 String MerchantCode = PropertyReader.getValue("MerchantCode"); 10 11 /**

Spring中Bean及@Bean的理解

Bean在Spring和SpringMVC中无所不在,将这个概念内化很重要,下面分享一下我的想法: 一.Bean是啥 1.Java面向对象,对象有方法和属性,那么就需要对象实例来调用方法和属性(即实例化): 2.凡是有方法或属性的类都需要实例化,这样才能具象化去使用这些方法和属性: 3.规律:凡是子类及带有方法或属性的类都要加上注册Bean到Spring IoC的注解: 4.把Bean理解为类的代理或代言人(实际上确实是通过反射.代理来实现的),这样它就能代表类拥有该拥有的东西了 5.我们都在微

Spring中的bean

1.定义和别名 定义一个bean可以为其制定如下属性 default-lazy-init:延迟初始化(默认false,即立即初始化) default-merge:从父类合并继承属性值 default-autowire:可以按byName,byType等方式完成自动装配 default-autowire-candidates:自动装配时候排除此bean bean可以使用id定义唯一名字,还可以使用name定义别名,例如<bean id="person" name="#ab