好好编程-物流项目06【Spring整合】

logistics-manager-service项目中创建对应的package

在这里插入图片描述

2.事务配置文件

项目中事务肯定是需要开启的,所以我们单独添加一个事务管理的配置文件,如下图

在这里插入图片描述

说明:applicationContext-trans.xml文件的内容如下所示。其中事务的传播行为需要说明一下,当接口名以save、insert、add、create、delete、upate开头时spring会自动帮我们开启事务(前提是我们配置了事务传播行为),而find、select、get开头的接口是查询,不涉及更改数据库,因此不需要事务,spring不会为查询接口自动开启事务。下面再说说切面,也就是事务的作用范围, execution(* com.bobo.service..(…)) 的意思是,com.bobo.service下的任意类的任意方法的任意参数及任意返回值都是事务的切入点。

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”

xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

<bean id=“transactionManager”

class=“org.springframework.jdbc.datasource.DataSourceTransactionManager”>

<tx:advice id=“txAdvice” transaction-manager=“transactionManager”>

tx:attributes

<tx:method name=“save*” propagation=“REQUIRED” />

<tx:method name=“insert*” propagation=“REQUIRED” />

<tx:method name=“add*” propagation=“REQUIRED” />

<tx:method name=“create*” propagation=“REQUIRED” />

<tx:method name=“delete*” propagation=“REQUIRED” />

<tx:method name=“update*” propagation=“REQUIRED” />

<tx:method name=“find*” propagation=“SUPPORTS” read-only=“true” />

<tx:method name=“select*” propagation=“SUPPORTS” read-only=“true” />

<tx:method name=“get*” propagation=“SUPPORTS” read-only=“true” />

</tx:attributes>

</tx:advice>

aop:config

<aop:advisor advice-ref=“txAdvice”

pointcut=“execution(* com.bobo.service..(…))” />

</aop:config>

web.xml中注册


我们创建的3个Spring的配置文件,相互之间是独立的,我们需要在logistics-manager-web项目的web.xml文件中配置,在服务器初始化的时候加载。

在这里插入图片描述

配置内容为:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version=“2.5” id=“WebApp_ID” xmlns=“http://java.sun.com/xml/ns/javaee”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

taotao-manager

index.jsp

contextConfigLocation

classpath:spring/applicationContext-*.xml

Docker步步实践

目录文档:

①Docker简介

②基本概念

③安装Docker

④使用镜像:

⑤操作容器:

⑥访问仓库:

⑦数据管理:

⑧使用网络:

⑨高级网络配置:

⑩安全:

⑪底层实现:

⑫其他项目:

(img-A3X4kmwx-1714677057495)]

⑩安全:

[外链图片转存中…(img-4NMeOLom-1714677057495)]

⑪底层实现:

[外链图片转存中…(img-KPa7BoBs-1714677057496)]

⑫其他项目:

[外链图片转存中…(img-tIKxUWwN-1714677057496)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 13
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值