zoukankan      html  css  js  c++  java
  • spring 常用配置

    1.引入properties文件

    <!-- spring2.0需要配置PropertyPlaceholderConfigurer,为location属性注入值 -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties"></property>
    </bean
        
    <!-- spring2.5之后 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    
    <!-- 在配置文件中使用${propName}获取外部属性文件的值 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="user" value="${jdbc.user}"></property>
        <property name="password" value="${jdbc.password}"></property>
        <property name="jdbcUrl" value="${jdbc.url}"></property>
        <property name="driverClass" value="${jdbc.driverClass}"></property>
        <property name="initialPoolSize" value="${jdbc.initpool}"></property>
        <property name="maxPoolSize" value="${jdbc.maxpool}"></property>
    </bean>
    

    2.自动扫描包

    <!-- 自动扫描包,只扫描Controller -->
    <context:component-scan base-package="com.pdsu"/>
    
    <!-- 更详细的配置 -->
    <context:component-scan base-package="com.pdsu" use-default-filters="false">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    
    • use-default-filters

    使用默认的 Filter 进行包扫描,而默认的 Filter 对标有 @Service,@Controller和@Repository 的注解的类进行扫描,默认值为true,当此值为false时,需要配合<context:include-filter />注解使用。

  • 相关阅读:
    Linux多线程Pthread学习小结
    TCP三次握手/四次挥手
    内存管理内幕
    Delphi 中分发设计时包
    一个小的算法问题解决
    写了一个验证数字范围的正则表达式
    用 XML 文件持久化和恢复图片信息
    string.Empty 和 "" 并不总是可以互换的
    博客园用的 FreeTextBox 有 bug
    乱花渐欲迷人眼。。。
  • 原文地址:https://www.cnblogs.com/dch0/p/11440635.html
Copyright © 2011-2022 走看看