报错的问题
package com.wp.demo3;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class Around implements MethodInterceptor{
public Object invoke(MethodInvocation invocation) throws Throwable {
// TODO Auto-generated method stub
System.out.println("环绕前置增强");
Object obj = invocation.proceed();
System.out.println("环绕后置增强");
return obj;
}
}
package com.wp.demo3;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.MethodBeforeAdvice;
public class Before implements MethodBeforeAdvice{
public void before(Method method, Object[] args, Object target) throws Throwable {
// TODO Auto-generated method stub
System.out.println("前置增强");
}
}
package com.wp.demo3;
public class ProductDao {
public void save() {
// TODO Auto-generated method stub
System.out.println("保存商品....");
}
public void updata() {
// TODO Auto-generated method stub
System.out.println("修改商品....");
}
public void delete() {
// TODO Auto-generated method stub
System.out.println("删除商品....");
}
public void find() {
// TODO Auto-generated method stub
System.out.println("查询商品....");
}
package com.wp.demo3;
public interface UserDao {
public void save();
public void updata();
public void delete();
public void find();
}
package com.wp.demo3;
public class UserDaoImpl implements UserDao {
public void save() {
// TODO Auto-generated method stub
System.out.println("保存用户....");
}
public void updata() {
// TODO Auto-generated method stub
System.out.println("修改用户....");
}
public void delete() {
// TODO Auto-generated method stub
System.out.println("删除用户....");
}
public void find() {
// TODO Auto-generated method stub
System.out.println("查询用户....");
}
}
package com.wp.demo3;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:demo3.xnl")
public class Demo3 {
@Resource(name = "userDao")
private UserDao userDao;
@Resource(name = "productDao")
private ProductDao productDao;
@Test
public void test() {
userDao.delete();
userDao.find();
userDao.save();
userDao.updata();
productDao.delete();
productDao.find();
productDao.save();
productDao.updata();
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wp</groupId>
<artifactId>spring-aop</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring-aop Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>spring-aop</finalName>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id = "userDao" class = "com.wp.demo3.UserDaoImpl"/>
<bean id = "productDao" class = "com.wp.demo3.ProductDao"/>
<bean id = "myBefore" class = "com.wp.demo3.Before"/>
<bean id = "myAround" class = "com.wp.demo3.Around"/>
<bean class = "org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name = "benaName" value = "*Dao"/>
<property name = "interceptorNames" value="myBefore"/>
</bean>
</beans>
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星