报错的问题

报错的问题

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

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕珊 2019-03-21 19:55:38

你好!两个拼写错误:

1、如下所示,应该是xml,不是xnl

http://img1.sycdn.imooc.com//climg/5c937b590001511604460084.jpg

2、demo3.xml文件中,如下选中的单词应该是beanNames

http://img1.sycdn.imooc.com//climg/5c937b8e00013ffe05380134.jpg

建议下次将报错提示也贴出来。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 提问者 慕仔1940952 #1
    修改后仍然报错 java.lang.IllegalStateException: Failed to load ApplicationContext
    2019-03-22 12:56:20
  • chrismorgen 回复 提问者 慕仔1940952 #2
    你好同学,建议你将报错提示粘贴完整,方便我们从中获取有价值的信息哦,并具有针对性的为你解答,祝学习愉快~
    2019-03-22 15:11:21
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
SSM主流框架入门与综合项目实战2018版
  • 参与学习           人
  • 提交作业       205    份
  • 解答问题       4317    个

Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师