配置文件

SpringIOC相关配置:

<bean id="" class=""></bean>   id为唯一标识,class用于指定类
给属性赋值:name为set方法去掉set后小写首字母的名称,value是给非引用类型赋值,ref是给引用类型赋值
(xml配置文件采用调用set方法赋值,所以要求必须有set方法)
    <property name="" value=""/>
    <property name="" value=""/>
例1:
    <bean id="userService" class="com.server.UserService">
        <property name="name" value="张三"/>
        <property name="age" value="18"/>
    </bean>
例2:(给引用类型赋值时,ioc容器中需要有对应的Bean)
    <bean id="userService" class="com.server.UserService">
        <property name="UserDao" ref="userDao"/>
    </bean>
例3:内部Bean(外部不可用,只给当前Bean使用)
    <bean id="userService" class="com.server.UserService">
        <property name="UserDao">
            <bean class="com.server.UserDao" />
        </property>
    </bean>

引入配置文件(properties)
<context:property-placeholder location=”jdbc.properties”/>
获取容器中的值 ${key}

配置Bean作用域

scope属性 指定对象创建单例或多例
singleton 默认单例
prototype 多例

SpringAOP相关配置:
<aop:aspectj-autoproxy /> 开启aspectj aop注解的支持

纯XML方式配置AOP:
aop:config //配置aop
<aop:pointcut id=”pc” expression=”execution(* com.server.SpringAOP.*.*(..))”/> //声明切点表达式
aop:aspect
<aop:before method=”Begin” pointcut-ref=”pc”/> //配置前置通知,method为通知方法名,pointcut-ref为execution配置
<aop:after method=”End” pointcut-ref=”pc”/>//配置后置通知,method为通知方法名,pointcut-ref为execution配置
<aop:after-throwing method=”Exception” pointcut-ref=”pc”/>//配置异常通知,method为通知方法名,pointcut-ref为execution配置
<aop:after-returning method=”Return” pointcut-ref=”pc”/>//配置返回通知,method为通知方法名,pointcut-ref为execution配置
<aop:around method=”notify” pointcut-ref=”pc”/>//配置环绕通知,method为通知方法名,pointcut-ref为execution配置

spring-tx相关配置:
<tx:annotation-driven transaction-manager=”transactionManager”/> 配置事务管理器的事务实现


配置contextConfigLocation

contextConfigLocation
classpath:applicationContext.xml

配置启动 Spring 框架的监听器

org.springframeworkweb.context.ContextLoaderListener
监听ContextLoaderListener,启动后会调用方法,并获取name为contextConfigLocation的值