【Spring实战4】06---装配Bean(xml)

通过XML装配Bean

创建XML配置规范

如下Spring XML配置所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-xsd">
        <bean id="car" class="nh.spring.ioc.beans.Car">
            <property name="brand" value="Ca11"/>
            <property name="color" value="blue"/>
        </bean>

        <bean id="runCar" class="nh.spring.ioc.beans.RunCar">
            <constructor-arg value="#{T(System).out}"/>
        </bean>

        <aop:config>
            <aop:aspect ref="runCar">
                <aop:pointcut id="show" expression="execution(* show())"/>
                <aop:before method="carBeforeRun" pointcut-ref="show"/>
                <aop:after method="carAfterRun" pointcut-ref="show"/>
            </aop:aspect>
        </aop:config>
</beans>

在使用XML时,需要在配置文件的声明多个xml模式xsd,定义配置spring的xml元素

bean都包含在 <beans>元素中

构造器注入

<constructor-arg ref="">

原文地址:https://www.cnblogs.com/hylinux/p/6027236.html