亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我的輸出結果沒有MoocAspect before,只有AspectBiz呢?怎么覺得是配置文件沒有生效??

配置文件如下:

<?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-4.0.xsd">

? ? ? ?

? ? ? ?<bean id="moocAspect" class="com.imooc.aop.schema.advice.MoocAspect"></bean>

<bean id="aspectBiz" class="com.imooc.aop.schema.advice.AspectBiz"></bean>

<aop:config>

<aop:aspect id="moocAspectAOP" ref="moocAspect">

<aop:pointcut expression="execution(* com.imooc.aop.schema.advice.biz.*Biz.*(..))" id="moocPoint"/>?

? <aop:before method="before" pointcut-ref="moocPoint"/>

? </aop:aspect>

? </aop:config>?

?</beans>


輸出結果:

三月 06, 2016 8:42:08 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh

INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5bc22f22: startup date [Sun Mar 06 20:42:08 CST 2016]; root of context hierarchy

三月 06, 2016 8:42:08 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

INFO: Loading XML bean definitions from URL [file:/D:/Program%20Files%20(x86)/eclipse-jee-luna-SR2-win32-x86_64/eclipse/D/workspace/spring/bin/spring-aop-schema-aspect.xml]

AspectBiz

三月 06, 2016 8:42:08 下午 org.springframework.context.support.AbstractApplicationContext doClose

INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@5bc22f22: startup date [Sun Mar 06 20:42:08 CST 2016]; root of context hierarchy


正在回答

3 回答

試一下在execution()里面的*后空一格,在寫包那些方法

3 回復 有任何疑惑可以回復我~
#1

謝同學謝童鞋 提問者

是的,就是這個錯誤,已經解決,非常感謝!
2016-04-12 回復 有任何疑惑可以回復我~
#2

二度

同謝~~~
2016-07-31 回復 有任何疑惑可以回復我~
#3

小小幻術師

分析半小時沒發現問題,用你的方法解決了,再次感謝!
2017-05-08 回復 有任何疑惑可以回復我~

package com.imooc.aop.schema.advice;

public class AspectBiz {

public void biz(){

System.out.println("AspectBiz");

//throw new RuntimeException();

}

}


package com.imooc.aop.schema.advice;

import org.aspectj.lang.ProceedingJoinPoint;

public class MoocAspect {

public void before(){

System.out.println("MoocAspect before");

}

public void afterReturning(){

System.out.println("MoocAspect after");

}

public void afterThrowing(){

System.out.println("MoocAspect throwing");

}

public void after(){

System.out.println("MoocAspect after");

}

public Object around(ProceedingJoinPoint pjp){

Object obj = null;

try {

System.out.println("MoocAspect around 1");

obj = pjp.proceed();

System.out.println("MoocAspect around 2");

} catch (Throwable e) {

e.printStackTrace();

}

return obj;

}

}


package com.imooc.aop.schema.test;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.junit.runners.BlockJUnit4ClassRunner;

import com.imooc.aop.schema.advice.AspectBiz;

import com.imooc.test.UnitTestBase;

@RunWith(BlockJUnit4ClassRunner.class)

public class TestAOPSchemaAdvice extends UnitTestBase{

public TestAOPSchemaAdvice(){

super("classpath*:spring-aop-schema-aspect.xml");

}

@Test

public void testBiz(){

AspectBiz biz = super.getBean("aspectBiz");

biz.biz();

}

}

http://img1.sycdn.imooc.com//56e0dfb0000140f002460146.jpg

0 回復 有任何疑惑可以回復我~
#1

兮蓅

您好,請問為什么您MoocAspect類中需要導入org.aspectj.lang.ProceedingJoinPoint包?
2016-12-08 回復 有任何疑惑可以回復我~
#2

兮蓅 回復 兮蓅

我知道了
2016-12-08 回復 有任何疑惑可以回復我~

要不要把java文件也貼上來,這樣更容易確定問題

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么我的輸出結果沒有MoocAspect before,只有AspectBiz呢?怎么覺得是配置文件沒有生效??

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號