不用类连接数据库—Spring Elements-Spring beans

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"         
        destroy-method="close">         
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />        
    <property name="url" value="jdbc:mysql://localhost:3306/demo?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false" />        
    <property name="username" value="root" />        
    <property name="password" value="root" />        

    </bean> 

*************************************************

<?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:tx="http://www.springframework.org/schema/tx" 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.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"         
        destroy-method="close">         
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />        
    <property name="url" value="jdbc:mysql://localhost:3306/demo?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false" />        
    <property name="username" value="root" />        
    <property name="password" value="root" />        
    </bean> 
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/group1/po/Card.hbm.xml</value>
<value>com/group1/po/Log.hbm.xml</value>
<value>com/group1/po/Depositor.hbm.xml</value>
<value>com/group1/po/EmployeeRole.hbm.xml</value>
<value>com/group1/po/Employee.hbm.xml</value>
<value>com/group1/po/Rates.hbm.xml</value>
</list>
</property>
</bean>
<!-- **************************begin********************************** -->
<!-- 2、事务管理器:指定由谁来监管事务 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 3、事务通知:指定方法所采取的事务传播策略 -->
<tx:advice id="x" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="do*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!-- 4、整合:给满足要求的业务类声明事务 -->
<aop:config>
<aop:pointcut expression="execution(* com.group1.serviceimpl.*.*(..))"
id="m" />
<aop:advisor advice-ref="x" pointcut-ref="m" />
</aop:config>
<!-- **************************end********************************** -->


<!-- 配置Dao -->
<bean id="cardDao" class="com.group1.daoimpl.CardDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="currencyDao" class="com.group1.daoimpl.CurrencyDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
<property name="ratesDao" ref="ratesDao"></property>
</bean>
<bean id="depositorDao" class="com.group1.daoimpl.DepositorDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="employeeDao" class="com.group1.daoimpl.EmployeeDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="logDao" class="com.group1.daoimpl.LogDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="ratesDao" class="com.group1.daoimpl.RateDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置Service -->
<bean id="cardBOService" class="com.group1.serviceimpl.CardBOServiceImpl">
<property name="cardDao" ref="cardDao"></property>
</bean>
<bean id="currencyBOService" class="com.group1.serviceimpl.CurrencyBOServiceImpl">
<property name="currencyDao" ref="currencyDao"></property>
</bean>
<bean id="depositorAndCardBOService" class="com.group1.serviceimpl.DepositorAndCardBOServiceImpl">
<property name="depositorDao" ref="depositorDao"></property>
<property name="cardDao" ref="cardDao"></property>
</bean>
<bean id="employeeBOService" class="com.group1.serviceimpl.EmployeeBOServiceImpl">
<property name="employeeDao" ref="employeeDao"></property>
</bean>
<!-- 配置Action -->
<bean class="com.group1.action.CardBOAction" id="cardBOAction">
<property name="cardBOService" ref="cardBOService" />
</bean>
<bean class="com.group1.action.DepositorAndCardBOAction" id="depositorAndCardBOAction">
<property name="depositorAndCardService" ref="depositorAndCardBOService" />
</bean>
<bean class="com.group1.action.EmployeeBOAction" id="employeeBOAction">
<property name="employeeBOService" ref="employeeBOService" />
</bean>
<bean class="com.group1.action.CurrencyBoAction" id="currencyBOAction">
<property name="currencyBOService" ref="currencyBOService" />
</bean>
<!-- 配置Aspect -->
<bean id="authority" class="com.group1.authorityAspect.AuthorityAspect"></bean>
<bean id="cardValidater" class="com.group1.validaterAspect.CardValidaterAspect">
<property name="carddao" ref="cardDao"></property>
</bean>
<bean id="log" class="com.group1.logAspect.LoggerAspect">
<property name="dao" ref="logDao"></property>
</bean>
<bean id="employeeValidater" class="com.group1.validaterAspect.EmployeeValidaterAspect">
<property name="employeedao" ref="employeeDao"></property>
</bean>
<!-- 配置自动代理 -->
<bean id="proxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>cardBOService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>cardValidater</value>
<value>authority</value>
<value>log</value>
</list>
</property>
</bean>
<bean id="proxy1"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>employeeBOService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>employeeValidater</value>
<value>log</value>
</list>
</property>
</bean>
<bean id="proxy2"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>depositorAndCardBOService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>log</value>
</list>
</property>
</bean>
<bean id="proxy3"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>currencyBOService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>authority</value>
<value>log</value>
</list>
</property>
</bean>
</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值