1、spring解决了什么问题
类与类之间强耦合的问题
2、控制反转:一个对象依赖的其它对象会通过被动的方式传递进来,而不是这个对象自己创建或者查找依赖对象
3、注入方法:属性注入,需要为每一个依赖类创建相应的getter和setter方法。
构造方法注入,需要为依赖类创建相应的构造方法 。
内置对象:
<property name="被注入的bean的名字" ref="被注入的类的beanId"></property>
自定义对象注入:
<property name="email"><ref bean="emailid"/></property>
list注入:
<property name="hobby"><list><value>读书</value><value>讨债</value></list></property>
scope:是否为单例,singleton单例 prototype非单例
@Repository:一般用于Dao的注入;@Service:一般用于Service层的注入;@Controller:一般用于Action层的注入。
AOP:对业务的辅助 嵌入业务完成一些功能
代理模式有权限控制是否调用真实的目标方法 装饰模式必须调用目标方法
AOPxml配置
<aop:config>
<aop:pointcut expression="execution(* com.*.*(..))" //包名-方法-参数 id="servicepointcut"/>
<aop:aspect ref="方法所在的类" ><aop:around method=" 方法名 " pointcut-ref="切面id " /></aop:aspect>
<aop:pointcut expression="execution(* com.*.*(..))" //包名-方法-参数 id="servicepointcut"/>
<aop:aspect ref="方法所在的类" ><aop:around method=" 方法名 " pointcut-ref="切面id " /></aop:aspect>
</aop:config>