spring基础使用

ApplicationContext.xml

Spring使用方法

<?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:p="http://www.springframework.org/schema/p"
       xmlns:c="http://www.springframework.org/schema/c"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
    <!-- 由 Spring容器创建该类的实例对象 -->
<!--    三种构造器创建对象的方法-->
    <bean id="hello1" class="com.yao.Pojo.hello">
        <property name="name" value="yzb"/>
        <property name="number" value="15327454472"/>
        <constructor-arg index="0" value="ylb"/>
        <constructor-arg index="1" value="15154121346"/>
    </bean>
    <bean id="hello2" class="com.yao.Pojo.hello">
        <constructor-arg type="java.lang.String" value="ylb"/>
        <constructor-arg type="java.lang.String" value="151516"/>
    </bean>
<!--    p方式注入,通过值直接注入-->
    <bean id="hello3" class="com.yao.Pojo.hello" p:name="ss" p:number="ss"/>
<!--    c构造器注入,通过构造器注入-->
    <bean id="hello4" class="com.yao.Pojo.hello" c:name="ss" c:number="ss"/>

<!--    单例模式 scope="singleton" 原型模式 scope="prototype"-->
    <bean id="address" class="com.yao.Pojo.Address"/>
    <bean id="Student" class="com.yao.Pojo.Student">
        <property name="name" value="yzb"/>
        <property name="address" ref="address"/>
        <property name="books">
            <array>
                <value>aa</value>
                <value>bb</value>
                <value>cc</value>
            </array>
        </property>
        <property name="hobby">
            <list>
                <value>aaa</value>
                <value>bbb</value>
                <value>ccc</value>
            </list>
        </property>
        <property name="card">
            <map>
                <entry key="1" value="aaaa"/>
                <entry key="2" value="bbbb"/>
                <entry key="3" value="cccc"/>
            </map>
        </property>
        <property name="games">
            <set>
                <value>sss</value>
                <value>ddd</value>
            </set>
        </property>
        <property name="wife">
            <null/>
        </property>
        <property name="info">
            <props>
                <prop key="stuNO">1900130517</prop>
            </props>
        </property>
    </bean>
    <bean id="log" class="com.yao.log.log"/>
    <bean id="afterLog" class="com.yao.log.AfterLog"/>
    <bean id="student1" class="com.yao.Pojo.Student1"/>
    <bean id="allLog" class="com.yao.log.allLog"/>
    <bean id="annotationLog" class="com.yao.log.AnnotationLog"/>
    <aop:aspectj-autoproxy/>
<!--    <aop:config>-->
<!--        <aop:pointcut id="pointcut" expression="execution(* com.yao.Pojo.Student1.*(..))"/>-->
<!--        <aop:advisor advice-ref="log" pointcut-ref="pointcut"/>-->
<!--        <aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/>-->
<!--        <aop:aspect ref="allLog">-->
<!--            <aop:pointcut id="point" expression="execution(* com.yao.Pojo.Student1.*(..))"/>-->
<!--            <aop:before method="Before" pointcut-ref="point"/>-->
<!--            <aop:after method="After" pointcut-ref="point"/>-->
<!--        </aop:aspect>-->
<!--    </aop:config>-->

</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值