使用配置文件开启IOC
注入时,配置bean,property,最后通过context.getbean获取bean对象,不可以通过@Autowired注入
使用注解开启IOC,
配置文件不用配bean,加上<context: component-scan>,可以使用Autowired注入
完全不用xml开启IOC,
用@Configuration加到一个类,使该类成为配置类,相当于标签。加上@ComponentScan(“包”)扫描包下所有bean
通过@Import导入一个配置类
在配置类上加上@PropertySource可以读取配置文件中的键值对
使用配置文件开启AOP
<aop:config>
<aop:pointcut expression="execution(* com.itheima.service.impl.*.*(..))" id="a"/>
<aop:aspect id="txAdvice" ref="txManager">
<aop:around method="transactionAround" pointcut-ref="a"/>
<aop:around method="commit" pointcut-ref="a"/>
</aop:aspect>
</aop:config>
开启注解开启AOP
切面类加上@Aspect @Compent
定义一个方法a()上面加上@pointcut(“业务类路径”)作为切点pointcut
下面定义切面方法方法
@Before(execution"a()")前置通知
@AfterReturning(execution"a()")后置通知
@AfterThrowing(execution"a()")异常通知
@After(execution"a()")最终通知
@Around(execution"a()")环绕通知
配置文件加上<aop:aspectj-autoproxy/>
完全不使用xml开启AOP
定义一个类加上
@Configuration
@ComponentScan(basePackages=“com.itheima”)
@EnableAspectJAutoProxy//开启aspectj