百度云资料地址:
链接:https://pan.baidu.com/s/1RNLCemXqV2fehqE7bE4JeA 提取码:tzrd
gitee代码地址:
https://gitee.com/liushanshan126/spring-guigu-study




在beans中加入:xmlns:p=“http://www.springframework.org/schema/p”
使用方式如下:


参考6


普通bean:上面使用到的都是普通bean,在配置文件中定义bean类型就是返回类型
工厂bean:在配置文件定义bean类型可以和返回类型不一样


默认bean为单例,可以手动设置为多例
式例:


xml配置:

实体类配置:

测试类配置和实现结果:

后置处理器配置:


byType和byName,可以省略property(有ref)的属性注入

1:需要引入context的bean
2:需要一个外部文件properties或者yml
3:使用context标签将外部文件引入进来
4:使用${}获取外部文件里面的配置
1:放入aop包

2:创建类加入注解

3:创建xml,进行自动扫描

4:测试


1:@Autowired:根据属性类型进行属性注入
2:@Qualifier:根据属性名称进行属性注入
@Autowired可以单独使用,类型不能满足则使用名称,可以加入@Qualifiery一起使用

3:@Resource:可以根据类型或者名称来进行属性注入

(1)面向切面编程(方面),利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。
(2)通俗描述:不通过修改源代码方式,在主干功能里面添加新功能
(3)使用登录例子说明AOP
有接口的情况

1:接口和实现类

2:使用proxy类中的方法

实际上的student就是一个代理对象,使用里面的方法就会调用里面的invoke方法
3:动态代理类

没有接口的情况







package com.bear.aoptest.aspectj测试;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
/**
* <简述> aspectj测试
* <详细描述>
*
* @author LiuShanshan
* @version $Id$
*/
@Aspect
@Component
public class AspectJTest {
// ** execution为aspect固定语句
// 前置通知
@Before(value = "execution(* com.bear.aoptest.aspectj测试.Teacher.*(..))")
public void before(JoinPoint point){ // JoinPoint切入点,被增强的方法
// Object[] args = point.getArgs();
// for (Object arg : args) {
// System.out.println(arg);
// }
System.out.println("before,在方法执行之前执行");
}
// 后置通知(返回通知)
@AfterReturning(value = "execution(* com.bear.aoptest.aspectj测试.Teacher.*(..))")
public void afterReturning(){
System.out.println("afterReturning");
}
// 异常通知
@AfterThrowing(value = "execution(* com.bear.aoptest.aspectj测试.Teacher.*(..))")
public void afterThrowing() throws Throwable {
System.out.println("异常通知");
}
// 环绕通知
@Around(value = "execution(* com.bear.aoptest.aspectj测试.Teacher.*(..))")
public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("环绕通知之前");
// 增强的方法执行
proceedingJoinPoint.proceed();
System.out.println("环绕通知之后");
}
// 最终通知
@After(value = "execution(* com.bear.aoptest.aspectj测试.Teacher.*(..))")
public void after(){
System.out.println("after,方法执行之后执行");
}
}




7种事务的隔离级别:


可重复读是mysql的默认隔离级别
配置类:
package com.bear.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
/**
* <简述>
* <详细描述>
*
* @author LiuShanshan
* @version $Id$
*/
@Configuration
@ComponentScan("com.bear") // 组件扫描
@EnableTransactionManagement // 开启事务
public class TxConfig {
//创建数据库连接池
@Bean()
public DruidDataSource getDruidDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql:///test");
dataSource.setUsername("root");
dataSource.setPassword("root");
return dataSource;
}
//创建JdbcTemplate对象
@Bean
public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
//到ioc容器中根据类型找到dataSource
JdbcTemplate jdbcTemplate = new JdbcTemplate();
//注入dataSource
jdbcTemplate.setDataSource(dataSource);
return jdbcTemplate;
}
//创建事务管理器
@Bean
public DataSourceTransactionManager getDataSourceTransactionManager(DataSource dataSource) {
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
transactionManager.setDataSource(dataSource);
return transactionManager;
}
}
servie层(配置事务的一层):

测试代码:
// 配置类
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigTest.class);
ServiceTest serviceTest = context.getBean("serviceTest", ServiceTest.class);
serviceTest.get();
第一非阻塞式:在有限资源下,提高系统吞吐量和伸缩性,以Reactor为基础实现响应式编程
第二函数式编程:Spring5框架基于java8,Webflux使用Java8函数式编程方式实现路由请求

第一两个框架都可以使用注解方式,都运行在Tomet等容器中
第二SpringMVC采用命令式编程,Webflux采用异步响应式编程