1.配置文件:
web配置:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.注入:
junit测试:
3.使用注解进行注入:
4.自动扫描class管理bean:
扫描的类应该含有@Repository@Controller@Service等标记
4.aop:
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<aop:aspectj-autoproxy />//开启aop注释
<context:annotation-config />
<!--
<context:component-scan base-package="quanquanfly" />
-->
<bean id="check" class="quanquanfly.Check" init-method="init"
destroy-method="destroy" />
<bean id="test" class="quanquanfly.Test" />
<bean id="testimpl" class="quanquanfly.TestImpl">
</bean>
<bean id="myInterceptor" class="quanquanfly.Check1"/>
</beans>
@Before("anyMethod()")//定义前置通知
public void before()
{
System.out.println("前置通知");
}
@AfterReturning("anyMethod()")//定义后置通知
public void afterreturn()
{
System.out.println("后置通知");
}
@After("anyMethod()")//定义后置通知
public void after()
{
System.out.println("最终通知");
}
@AfterThrowing("anyMethod()")//出现例外通知的时候,不出现后置通知,其他通知都可以执行
public void throwing()
{
System.out.println("例外通知");
}
@Around("anyMethod()")
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("进入方法");
Object result = pjp.proceed();
System.out.println("退出方法");
return result;
}
}