当前位置: 首页 > news >正文

网站建设岗位风险防控微信商城定制

网站建设岗位风险防控,微信商城定制,成立公司需要什么条件,张家界做网站文章目录一、声明式事务之全注解式开发1、新建springConfig类2、测试程序3、测试结果二、声明式事务之XML实现方式1、配置步骤2、测试程序3、运行结果附一、声明式事务之全注解式开发 基于之前的银行转账系统#xff0c;将spring.xml配置文件嘎掉#xff0c;变成全注解式开发… 文章目录一、声明式事务之全注解式开发1、新建springConfig类2、测试程序3、测试结果二、声明式事务之XML实现方式1、配置步骤2、测试程序3、运行结果附一、声明式事务之全注解式开发 基于之前的银行转账系统将spring.xml配置文件嘎掉变成全注解式开发。 加入事务的银行转账 原spring.xml文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdcontext:component-scan base-packagecom.powernode.bank/context:component-scan!--配置数据源--bean iddataSource classcom.alibaba.druid.pool.DruidDataSourceproperty namedriverClassName valuecom.mysql.jdbc.Driver/propertyproperty nameurl valuejdbc:mysql://localhost:3306/dududu/propertyproperty nameusername valueroot/propertyproperty namepassword value123456/property/bean!--配置JDBCTemplate--bean idjdbcTemplate classorg.springframework.jdbc.core.JdbcTemplateproperty namedataSource refdataSource/property/bean!--配置事务管理器--bean idtxManager classorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource/property/bean!--事务注解驱动器--tx:annotation-driven transaction-managertxManager/tx:annotation-driven/beans1、新建springConfig类 1、Configuration表示代替spring.xml配置文件在这个类当中完成配置 2、ComponentScan(“com.powernode.bank”)代替spring.xml文件中的组件扫描 3、EnableTransactionManagement代替spring.xml文件中的事务注解驱动器 Configuration //表示代替spring.xml配置文件在这个类当中完成配置 ComponentScan(com.powernode.bank) EnableTransactionManagement //代替事务注解驱动器 public class springConfig { }spring.xml文件中还剩余3个bean都有属性、值。 !--配置数据源--bean iddataSource classcom.alibaba.druid.pool.DruidDataSourceproperty namedriverClassName valuecom.mysql.jdbc.Driver/propertyproperty nameurl valuejdbc:mysql://localhost:3306/dududu/propertyproperty nameusername valueroot/propertyproperty namepassword value123456/property/bean!--配置JDBCTemplate--bean idjdbcTemplate classorg.springframework.jdbc.core.JdbcTemplateproperty namedataSource refdataSource/property/bean!--配置事务管理器--bean idtxManager classorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource/property/bean4、Beanget方法并且get方法执行结束的返回值要求是spring.xml文件里bean标签的class对象 //spring框架看到这个Bean注解后会调用这个被标注的方法这个方法的返回值是一个Java对象这个Java对象会自动纳入IoC容器管理//返回的对象就是spring容器当中Bean对象Bean(name dataSource)public DruidDataSource getDataSource(){DruidDataSource dataSource new DruidDataSource();dataSource.setDriverClassName(com.mysql.jdbc.Driver);dataSource.setUrl(jdbc:mysql://localhost:3306/dududu);dataSource.setUsername(root);dataSource.setPassword(123456);return dataSource;}Bean(name jdbcTemplate)public JdbcTemplate getJdbcTemplate(DataSource dataSource){ //spring在调用这个方法的时候会自动给我们传递过来一个dataSource对象JdbcTemplate jdbcTemplate new JdbcTemplate();jdbcTemplate.setDataSource(dataSource);return jdbcTemplate;}Bean(name txManager)public DataSourceTransactionManager getTxManager(DataSource dataSource){DataSourceTransactionManager txManager new DataSourceTransactionManager();txManager.setDataSource(dataSource);return txManager;}2、测试程序 Testpublic void testNoXML(){ApplicationContext ac new AnnotationConfigApplicationContext(springConfig.class);AccountService accountService (AccountService) ac.getBean(accountService);try {accountService.transfer(act_001,act_002,10000);System.out.println(转账成功);}catch (Exception e){e.printStackTrace();System.out.println(转账失败);}}3、测试结果 模拟异常事务依然可以起作用钱不会丢。 二、声明式事务之XML实现方式 全XML式开发不使用注解。 那么原spring.xml文件中的事务注解驱动就需要嘎掉 !--事务注解驱动器--tx:annotation-driven transaction-managertxManager/tx:annotation-driven嘎掉之后那应该怎么添加事务 再创建一个工程 为了不和原来的混在一起 AccountServiceImpl业务实现类中基于事务的注解Transactional删掉原spring.xml文件中的事务注解驱动就需要嘎掉pom文件中添加aspectj依赖 1、配置步骤 第一步配置事务管理器第二步配置通知第三步配置切面 pps需要添加AspectJ的依赖、添加aop命名空间 !--配置通知--tx:advice idtxAdvice transaction-managertxManager!--配置通知的相关属性--tx:attributes!--之前所讲的事务属性都可以在这个标签中配置--tx:method nametransfer propagationREQUIRED rollback-forjava.lang.Throwable//tx:attributes/tx:advice!--配置切面--aop:configaop:pointcut idtxPointcut expressionexecution(* com.powernode.service..* (..))/aop:advisor advice-reftxAdvice pointcut-reftxPointcut/aop:advisor/aop:configtx:method name“transfer” propagation“REQUIRED” rollback-for“java.lang.Throwable”/这里一般不会写具体的方法可以采用通配符的方式。 tx:method name“save*” propagation“REQUIRED” rollback-for“java.lang.Throwable”/ tx:method name“delete*” propagation“REQUIRED” rollback-for“java.lang.Throwable”/ tx:method name“insert*” propagation“REQUIRED” rollback-for“java.lang.Throwable”/ tx:method name“modify*” propagation“REQUIRED” rollback-for“java.lang.Throwable”/ tx:method name“query*” propagation“REQUIRED” rollback-for“java.lang.Throwable”/ tx:method name“find*” propagation“REQUIRED” rollback-for“java.lang.Throwable”/ tx:method name“get*” propagation“REQUIRED” rollback-for“java.lang.Throwable”/ 等等 2、测试程序 Testpublic void testNoAnnotation(){ApplicationContext ac new ClassPathXmlApplicationContext(spring.xml);AccountService accountService ac.getBean(accountService, AccountService.class);try{accountService.transfer(act_001,act_002,20000);System.out.println(转账成功);}catch(Exception e){e.printStackTrace();System.out.println(转账失败);}}3、运行结果 模拟异常 空指针异常 事务回滚 钱不会丢 附 spring.xml配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdcontext:component-scan base-packagecom.powernode/context:component-scan!--配置数据源--bean iddataSource classcom.alibaba.druid.pool.DruidDataSourceproperty namedriverClassName valuecom.mysql.jdbc.Driver/propertyproperty nameurl valuejdbc:mysql://localhost:3306/dududu/propertyproperty nameusername valueroot/propertyproperty namepassword value123456/property/bean!--配置JDBCTemplate--bean idjdbcTemplate classorg.springframework.jdbc.core.JdbcTemplateproperty namedataSource refdataSource/property/bean!--配置事务管理器--bean idtxManager classorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource/property/bean!--配置通知--tx:advice idtxAdvice transaction-managertxManager!--配置通知的相关属性--tx:attributes!--之前所讲的事务属性都可以在这个标签中配置--tx:method nametransfer propagationREQUIRED rollback-forjava.lang.Throwable//tx:attributes/tx:advice!--配置切面--aop:configaop:pointcut idtxPointcut expressionexecution(* com.powernode.service..* (..))/aop:advisor advice-reftxAdvice pointcut-reftxPointcut/aop:advisor/aop:config /beans
http://www.hkea.cn/news/14525788/

相关文章:

  • 建设部网站预应力资质迅博威网站建设
  • 防水网站的外链如何找网站功能配置
  • 做代售机票网站程序oa办公系统软件哪家好
  • 天津做网站推广的公司社交网站开发背景
  • 网站建设 大纲手机网站设计平台
  • 电脑什么网站可以做长图攻略网站做app有什么意义
  • 织梦cms网站分页打不开网站建设费用核算科目
  • 义马网站建设电话杭州网站设计的公司
  • wordpress 移动站插件网站开发采用的技术方案说明
  • 正规品牌网站设计图片常德网站建设技术
  • 彩票网站开发定制网站服务器不稳定怎么办
  • 广州网站定做教程网站如何做中英文切换
  • 网站建设是否需形成无形资产上海网页制作设计营销
  • 网站优化建设苏州怎么做淘宝客网站赚钱
  • 河南网站建设优化dede网站 异步生成
  • 常州网站推广招聘网站怎么做
  • 网站如何推广行业个人网站做cpa
  • 网站空间送域名招商外包服务公司
  • 申请免费的网站seo怎么学在哪里学
  • 国外哪些网站有黄图湖南长沙公司
  • 腾讯云备案网站建设方案书北辰网站建设公司
  • 网站建设优化课程网站开发技术说明文档
  • 网页游戏平台网站一般网站开发的硬件要求
  • 网站建设参考文献英文书籍拖拽响应式网站建设公司
  • 企业网站建设平台的分析怎么制作外贸网站模板
  • 中国跨境电商出口平台如何做好网站推广优化
  • 最好的网站设计公司建立网站内容需要做的事
  • c2c网站方案互联网创新创业大赛项目计划书
  • 微网站建设市场分析wordpress 跳转首页
  • 丽水集团网站建设广西工程建设质量管理协会网站