Spring注解
一:aop中
1.必须标识该类为spring注解类--@Component
2.Aspect--标识该类的切面类
Before--标志该方法为前置通知
AfterReturning--标识该方法为后置通知
Around--标识该方法为环绕通知,该方法中必须包含参数ProceedingJoinPoint pjp 在pjp.proceed()方法之前为环绕前置,执行为执行连接点中方法,之后为环绕后置
AfterThrowing(pointcut="execution(* com.qinian.service.*.*(..))",throwing="ex")--标识该方法为异常通知,该注解必须配置throw,该方法必须配置Exception ex 参数,其中throw的值和参数名字必须一致
After--标识该方法为最终通知
3.
注解代替xml
Configuration---标志该类为sprign配置
ComponentScan("com.qinian")---扫描sprign注解
EnableAspectJautoProxy---开启SpringAop注解,默认开启aoc注解
二:tx中
Transactionl--该注解标识该类会进行事务管理,默认事务级别为required(必须的),如果想修改事务级别为required时,则需要在方法上面添加再次添加Transactionl注解,同时设置其属性propagation=Propagation.support,redaOnly=true;
Configuration: 表示该类为配置文件
ComponentScan("xx"): 扫描Spring注解
PropertySource("classpath;xx.properties"): 引入配置文件
Improt(xxx.class):引入指定文件(bena配置)
EnableTransactionManagement:开始事务管理
Value("${driver}"):注入配置文件中ke为driver的的值,注意${};
Bean(dataSource): 配置bena,其值为该bena的id
Qualifie("dataSource") 注入参数的值,其值表示该参数所注入的bean的id
三:aoc中
Component:标识该类为Spring不确定层管理
Repository:标识该类为Spring管理的dao层
Service:标识该类为Spring管理的Service层
Controller:标识该类为Spring管理的控制层
AutoWired:bena属性注入,默认类别,然后名字
Quqlifiter:指定名字注入,作为属性注入时必须和 AutoWired一起使用,可单独作为参数值注入
Value:基本类型+Str属性注入
Resource:属性注入,一般注入用改注解

浙公网安备 33010602011771号