Spring笔记(7) - 纯注解编程(完结)

Spring笔记七 - 纯注解编程(完结)

  • 作者: Wyt

1. 纯注解版AOP编程

1.1 搭建环境

1. 应用配置Bean
2. 注解扫描

1.2 开发步骤

1. 原始对象
	@Service(@Component)
	public class UserServiceImpl implements UserService {
   }
	
2. 创建切面类 (额外功能 切入点 组装切面)
	@Aspect
	@Component
	public class MyAspect {
   
    	@Arround("execution(* login(..))")
        public Object arround(ProceedingJoinPoint joinPoint) throws Throwable {
   
            System.out.println("--- aspect log ---");
            Object ret = joinPoint.proceed();
            return ret;
        }
	}

3. Spring的配置文件中
	<aop:aspectj-autoproxy/>
	@EnableAspectjAutoProxy: 在配置Bean添加注解

1.3 注解AOP细节分析

1. 代理创建方式的切换  JDK Cglib
	<aop:aspectj-autoproxy proxy-target-class=true|false/>
		ture: Cglib    (default)false: JDK
	@EnableAspectjAutoProxy(ProxyTargetClass = true|false)

2. springboot AOP的开发方式
	@EnableAspectjAutoProxy  (已设置好)
	
	1. 原始对象
        @Service(@Component)
        public class UserServiceImpl implements UserService {}
	
	2. 创建切面类 (额外功能 切入点 组装切面)
        @Aspect
        @Component
        public class MyAspect {
            @Arround("execution(* login(..))")
            public Object arround(ProceedingJoinPoint joinPoint) throws Throwable {
                System.out.println("--- aspect log ---");
                Object ret = joinPoint.proceed();
                return ret;
            }
        }
	
	*注意:
		Spring AOP 代理默认实现 JDK
		SpringBoot AOP 代理默认实现 Cglib

2. 纯注解版 Spring + MyBatis整合

2.1 基础配置 (配置Bean)

三部分:
1. 连接池
	<!--连接池-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/xxx?useSSL=false"/>
        <property name="username" value="root"/>
        <property name="password" value="xxx"/>
    </bean>

	@Bean
	@public DruidDataSource dataSource() {
		DruidDataSource dataSource = new DruidDataSouce();
		dataSource.setDriverClassName("");
		dataSource.serUrl();
		...
		return dataSource;
	}

2. SqlSessionFactoryBean
	<!--创建SqlSessionFactory SqlSessionFactoryBean-->
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!--entity包存放实体类-->
        <property name="typeAliasesPackage" value="包的路径名"/>
        <property name="mapperLocations">
            <list>
                <value>classpath:xxx.xxx.mapper/*Mapper.xml</value>
            </list&g
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Quantum_Wu

一起加油呀ヾ(◍°∇°◍)ノ゙

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值