Spring的核心配置模板

Spring的application.xml配置模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">

<!--指定注解扫描包-->
<context:component-scan base-package="com.lry.pojo"/>
<!--开启属性注解支持-->
<context:annotation-config/>
<!--aop的注解支持-->
<aop:aspectj-autoproxy/>

<!--注册Bean-->
<bean id="diy" class="com.lry.diy.DiyPointCut"/>
<bean id="userService" class="com.lry.service.UserServiceImpl"/>

<!--第一种方式:通过Spring API实现-->
<!--aop的配置-->
<aop:config>
<!--切入点:expression:表达式匹配要拦截的方法:-->
<!--
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern) throws-pattern?)
-->
<aop:pointcut id="pointcut" expression="execution(* com.lry.service.UserServiceImpl.*(..))"/>
<!--执行环绕; advice-ref执行方法 . pointcut-ref切入点-->
<aop:advisor advice-ref="beforeLog" pointcut-ref="pointcut"/>
<aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/>
</aop:config>

<!--第二种方式:自定义类来实现AOP-->
<!--aop的配置-->
<aop:config>
<aop:aspect ref="diy">
<aop:pointcut id="pointCut" expression="execution(* com.lry.service.UserServiceImpl.*(..))"/>
<aop:before method="before" pointcut-ref="pointCut"/>
<aop:after method="after" pointcut-ref="pointCut"/>
</aop:aspect>
</aop:config>

</beans>
Contents
  1. 1. Spring的application.xml配置模板
|