Spring2.0学习笔记(1)

http://www.springframework.org/docs/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html

spring2.0学习笔记(1)
下载地址:http://www.springframework.org/download

资料来源:使用Spring进行面向切面编程(AOP)具体的咚咚我就不写了,主要是写下我配置的事务处理。    首先要去官方下载包。把这几个都要copy到classpath spring.jar spring-aspects.jar spring-mock.jar 还有这个aspectjweaver.jar 这个包是在 spring-framework-2.0.1-with-dependencies.zip 是在这个包里。最开始我就是因为没有这个东西,找不到类的。

applicationContext.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”
    xmlns:tx=”http://www.springframework.org/schema/tx”
    xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”
    default-autowire=”byName” default-lazy-init=”true”]
    [bean id=”placeholderConfig”
        class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”]
        [property name=”location”]
            [value]classpath:config.properties[/value]
        [/property]
    [/bean]
    [!– 支持 @Transactional 标记 –]
    [tx:annotation-driven /]

    [!– 支持 @AspectJ 标记–]
    [aop:aspectj-autoproxy /]

    [!– 以AspectJ方式 定义 AOP –]
    [aop:config proxy-target-class=”true”]
        [aop:advisor
            pointcut=”execution(* com.xx.yy.dao.impl.*Impl.*(..))”
            advice-ref=”txAdvice” /]
            [aop:advisor
            pointcut=”execution(* com.xx.yy.service.impl.*Impl.*(..))”
            advice-ref=”txAdvice” /]
    [/aop:config]

    [!– 基本事务定义,使用transactionManager作事务管理,默认get*方法的事务为readonly,其余方法按默认设置.
        默认的设置请参考Spring文档事务一章. –]
    [tx:advice id=”txAdvice”]
        [tx:attributes]
            [tx:method name=”get*” read-only=”true” /]
            [tx:method name=”find*” read-only=”true” /]
            [tx:method name=”*” /]
        [/tx:attributes]
    [/tx:advice]
[/beans]

dataAccessContext-hibernate.xml

[?xml version=”1.0″ encoding=”UTF-8″?]
[!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN 2.0//EN” “http://www.springframework.org/dtd/spring-beans-2.0.dtd”]
[beans default-autowire=”byName” default-lazy-init=”true”]
    [bean id=”dataSource”
        class=”com.mchange.v2.c3p0.ComboPooledDataSource”
        destroy-method=”close”]
        [property name=”driverClass”]
            [value]${datasource.driverClassName}[/value]
        [/property]
        [property name=”jdbcUrl”]
            [value]${datasource.url}[/value]
        [/property]
        [property name=”user”]
            [value]${datasource.username}[/value]
        [/property]
        [property name=”password”]
            [value]${datasource.password}[/value]
        [/property]
    [/bean]

    [bean id=”hibernateProperties”
        class=”org.springframework.beans.factory.config.PropertiesFactoryBean”]
        [property name=”properties”]
            [props]
                [prop key=”hibernate.dialect”]
                    ${hibernate.dialect}
                [/prop]
                [prop key=”hibernate.show_sql”]
                    ${hibernate.show_sql}
                [/prop]
                [prop key=”hibernate.format_sql”]false[/prop]
                [prop key=”hibernate.use_sql_comments”]false[/prop]

                [prop key=”hibernate.c3p0.testConnectionOnCheckout”]
                    false
                [/prop]
                [prop key=”hibernate.c3p0.idle_test_period”]100[/prop]
                [prop key=”c3p0.testConnectionOnCheckout”]true[/prop]
                [prop key=”c3p0.minPoolSize”]10[/prop]
                [prop key=”hc3p0.maxPoolSize”]50[/prop]
                [prop key=”hc3p0.timeout”]600[/prop]
                [prop key=”c3p0.max_statement”]50[/prop]
                [prop key=”hibernate.c3p0.acquire_increment”]1[/prop]
                [prop key=”hibernate.c3p0.idle_test_period”]100[/prop]

            [/props]
        [/property]
    [/bean]
    [bean id=”sessionFactory”
        class=”org.springframework.orm.hibernate3.LocalSessionFactoryBean”]
        [property name=”dataSource”]
            [ref bean=”dataSource” /]
        [/property]
        [property name=”hibernateProperties”]
            [ref bean=”hibernateProperties” /]
        [/property]
        [property name=”mappingDirectoryLocations”]
            [list]
                [value]classpath:com/xx/yy/domain[/value]
            [/list]
        [/property]
    [/bean]

    [bean id=”transactionManager”
        class=”org.springframework.orm.hibernate3.HibernateTransactionManager”]
        [property name=”sessionFactory”]
            [ref bean=”sessionFactory” /]
        [/property]
    [/bean]
    [!– Hibernate Template Defintion –]
    [bean id=”hibernateTemplate”
        class=”org.springframework.orm.hibernate3.HibernateTemplate”]
        [property name=”sessionFactory”]
            [ref bean=”sessionFactory” /]
        [/property]
    [/bean]

    [bean id=”messageSource”
        class=”org.springframework.context.support.ResourceBundleMessageSource”]
        [property name=”basenames”]
            [list]
                [value]applicationMessages[/value]
            [/list]
        [/property]
    [/bean]
[/beans]

bean.xml

[?xml version=”1.0″ encoding=”UTF-8″?]
[!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans-2.0.dtd”]

[beans default-autowire=”byName” default-lazy-init=”true”]

    [bean id=”dirctDAO”
        class=”com.xx.yy..dao.impl.DirctDAOHibernaeImpl”]
        [property name=”sessionFactory” ref=”sessionFactory” /]
    [/bean]
    [bean id=”dirctService”
        class=”com.xx.yy.service.impl.DirctServiceImpl”]
        [property name=”dirctDAO” ref=”dirctDAO” /]
    [/bean]
[/beans]

在web.xml中添加上
[context-param]
        [param-name]contextConfigLocation[/param-name]
        [param-value]
            /WEB-INF/classes/applicationContext.xml,/WEB-INF/classes/dataAccessContext-hibernate.xml,/WEB-INF/classes/bean.xml
        [/param-value]
    [/context-param]


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值