老师,为什么我这个输出有问题?
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();
}
}
输出结果:
26
收起
正在回答 回答被采纳积分+1
java工程师2020版
- 参与学习 人
- 提交作业 9400 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星