老师,为什么我这个输出有问题?

老师,为什么我这个输出有问题?

package com.imooc.spring.ioc.entity;
import org.springframework.stereotype.Component;
@Component
public class BookShop {
public void sellingBooks(){
System.out.println("卖出一本java基础书籍");
}
}
package com.imooc.spring.ioc.entity;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class MethodPro {
@Before("execution(public * com.imooc..*.*(..))")
public void preSales(JoinPoint joinPoint){
System.out.println("=========售前服务============");
}
@After("execution(public * com.imooc..*.*(..))")
public void afterSales(JoinPoint joinPoint){
System.out.println("=========售后服务============");
}
}
<?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.imooc"/>
<aop:aspectj-autoproxy/>
</beans>
​package com.imooc.spring.ioc.entity;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringApplication {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext2.xml");
BookShop bookShop = context.getBean("bookShop", BookShop.class);
bookShop.sellingBooks();
}
}

输出结果:

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

正在回答 回答被采纳积分+1

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

1回答
好帮手慕小脸 2020-12-26 10:21:31

同学你好,测试运行上述贴出的代码是正确的,并未出现同学这种情况,如下所示:

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

建议同学尝试多次运行再试试

祝学习愉快~

  • 提问者 谁叫我这么坏 #1

    我试了好多次都是我上面那样的结果呢

    2020-12-26 10:27:26
  • 同学你好,

    1、建议同学下载课程源码并尝试运行,查看是否也出现上述这种情况

    2、建议同学清除idea缓存再试试,步骤如下:

    点击菜单的File,Invalidate-caches按钮

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

    祝学习愉快~

    2020-12-26 14:17:39
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

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