zoukankan      html  css  js  c++  java
  • spring学习1

    1.<context:property-placeholder/> :用于从外部属性文件中获取Bean的配置

    <context:property-placeholder location="db.properties"></context:property-placeholder>
        <bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="dataSource">
            <property name="user" value="${user}"></property>
            <property name="password" value="${password}"></property>
            <property name="driverClass" value="${diverClass}"></property>
            <property name="jdbcUrl" value="${jdbcUrl}"></property>
        </bean>

     2.SpEL的使用事例

    <bean class="com.ddf.spring.beans.spel.Person" id="person">
        <property name="name" value="汤姆"></property>
        <!--引用其他bean的属性-->
        <property name="city" value="#{address.city}"></property>
        <!--引用其他对象-->
        <property name="car" value="#{car}"></property>
        <!--逻辑运算-->
        <property name="info" value="#{car.price >= 300000 ? '金陵' : '白领'}"></property>
    </bean>

     3.配置bean的方法

    <!--1.静态工厂方法-->
    <bean id="car0"
          class="com.ddf.spring.beans.factory.StaticCarFactory"
          factory-method="getCar">
        <constructor-arg value="奥迪"></constructor-arg>
    </bean>
    
    <!--2.实例工厂方法-->
    <bean class="com.ddf.spring.beans.factory.InstanceCarFactory" id="carFactory"></bean>
    <bean id="car1" factory-bean="carFactory" factory-method="getCar">
        <constructor-arg value="长安"></constructor-arg>
    </bean>

     4. exclude-filter 子节点指定排除哪些指定表达式的组件(assignable:类)

    <context:component-scan
            base-package="com.ddf.spring.beans.annotation">
        <context:exclude-filter type="assignable"
                                expression="com.ddf.spring.beans.annotation.repository.UserRepository"/>
    </context:component-scan>

    5. include-filter 子节点指定排除哪些表达式的组件,需要配合use-default-filters使用(annotation)

    <context:component-scan
            base-package="com.ddf.spring.beans.annotation"
            use-default-filters="false">
        <context:include-filter type="annotation"
                                expression="org.springframework.stereotype.Repository"/>
    </context:component-scan>
  • 相关阅读:
    安装cloudbase-init和qga批处理
    Windows添加自定义服务、批处理文件开机自启动方法
    Windows批处理:自动部署常用软件(静默安装)
    windows auto activate
    XML转译字符
    Leetcode908.Smallest Range I最小差值1
    Leetcode917.Reverse Only Letters仅仅反转字母
    Leetcode896.Monotonic Array单调数列
    Leetcode905.Sort Array By Parity按奇偶排序数组
    Leetcode892.Surface Area of 3D Shapes三维形体的表面积
  • 原文地址:https://www.cnblogs.com/djdjfj/p/9086869.html
Copyright © 2011-2022 走看看