Spring重点小结
其他
2018-12-26 13:46:48
阅读次数: 0
☆Spring技术总结
※1个容器:ProxyFactoryBean factory
1、自己创建容器
1)不用配置文件,用纯java代码自己创建
ProxyFactoryBean factory = new ProxyFactoryBean();//底层,一般不用
2)从Spring配置文件创建(位置在src根目录
ApplicationContext ctx = new ClassPathXmlApplicationContext
("cn/hncu/aop/demo6/demo6.xml");
2、拿项目中已经创建好的Application容器(有两种技术):
1)在普通Java类中,通过实现ApplicationContextAware接口,
该接口中的抽象方法的参数即是当前项目的容器对象。
2)在Web环境(如Servlet,Filter等能够获取ServletContext
这个Web容器的类)中,通过:ApplicationContext
ctx=WebApplicationContextUtils.getWebApplicationContext(getServletContext());
※AOP
公式:切面=切点+通知
advisor=pointcut+advice( before,after,around, afterreturning, afterthrowing)
@Aspect = @Pointcut + (@Before+@After+...)@Aspect = 字符串常量CUT +
(@Before+@After+...)
<aop:config>
<aop:aspect>
<aop:before method="..." pointcut="..."/>
<aop:around method="..." pointcut-ref="..."/>
</aop:aspect>
</aop:config>
※4种切面技术(根据切点分类):
1、RegexpMethodPointcutAdvisor---用正则表达式来定义切点 --最底层
2、AspectJExpressionPointcut ---用AspectJ切点语言来定义切点
3、注解 部分POJO--- @Transactional
4、标签 完全POJO
转载自blog.csdn.net/lx678111/article/details/83005060