标签:desc tar 地址 解析xml 包名 内存 XML 存储 返回
<bean id="userSevice" class="com.ljw.service.UserService">
<?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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd">
</beans>
spring_context.xml
配置文件中配置相关的设置spring_context.xml
配置文件中配置相关的设置spring_context.xml
配置文件中配置相关的设置测试:
注解详情请查看文章:注解 @Annotation
<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- bean definitions here -->
</beans>
@Scope(value="singleton")
单实例@Scope(value="prototype")
多实例用注解创建 dao 对象和 service 对象
再service类中创建dao类型的属性,并用注解注入对象,有两种方式
第一种:@Autowired
第二种:@Resource
导入基本jar包和AOP相关的jar包
<?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" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- bean definitions here -->
</beans>
package com.ljw.spring.annotation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;
@Component(value="userAdvice")
public class UserAdvice {
/**
* @description 前置通知
*/
public void userBefore() {
System.out.println("前置通知........");
}
/**
* @description 后置通知
*/
public void userAfter() {
System.out.println("后置通知........");
}
/**
* @description 环绕通知
* @param proceedingJoinPoint
* @throws Throwable
*/
public void userAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// 方法之前
System.out.println("方法之前..........");
// 执行增强的方法
proceedingJoinPoint.proceed();
// 方法之后
System.out.println("方法之后..........");
}
}
实现思想:把加载配置文件和创建对象过程,在服务器启动的时候完成
ServletContext servletContext = config.getServletContext();
ServletContext servletContext = this.getServletContext();
execution(<访问修饰符>?<返回类型><方法全名>(<参数>)<异常>)
execution(* com.ljw.spring.aop.User.add(..))
对User类的add方法增强execution(* com.ljw.spring.aop.User.*(..))
对User类的所有方法增强execution(* *.*(..))
对所有方法增强execution(* save*(..))
对所有save开头的方法增强标签:desc tar 地址 解析xml 包名 内存 XML 存储 返回
原文地址:https://www.cnblogs.com/ljw1994/p/11820321.html