java – 为什么这个Spring Aspect不能像方法参数一样打印?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 为什么这个Spring Aspect不能像方法参数一样打印?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2267字,纯文字阅读大概需要4分钟。
内容图文
![java – 为什么这个Spring Aspect不能像方法参数一样打印?](/upload/InfoBanner/zyjiaocheng/786/4e1b40d8ffb64c9d93c05be6d44c9c56.jpg)
Let me first foremention, the problem I’m facing is with the
interceptThoughts(String thoughts)
method, from the first code block, not printing
我正在运行Spring in Action的教程.有一个魔术师类用interceptThoughts(String ideas)和getThoughts()方法实现MindReader接口
@Aspect
public class Magician implements MindReader {
private String thoughts;
@Pointcut("execution(* com.underdogdevs.myspringaspectj."
+ "Thinker.thinkOfSomething(String)) && args(thoughts)")
public void thinking(String thoughts) {
}
@Override
@Before("thinking(thoughts)")
public void interceptThoughts(String thoughts) {
System.out.println("Intercepting volunteer's thoughts : " + thoughts);
this.thoughts = thoughts;
}
@Override
public String getThoughts() {
return thoughts;
}
}
该方面应该通过方法thinkOfSomething(字符串思想)阅读实现Thinker接口的志愿者的思想
public class Volunteer implements Thinker {
private String thoughts;
@Override
public void thinkOfSomething(String thoughts) {
this.thoughts = thoughts;
System.out.println("Something");
}
public String getThoughts() {
return thoughts;
}
}
我有我的java BeanConfig与魔术师和志愿者
@Configuration
public class BeanConfig {
@Bean
public MindReader magician() {
return new Magician();
}
@Bean
public Thinker volunteer() {
return new Volunteer();
}
}
而我正在尝试运行它以获得魔术师方法在interceptThoughts方法中打印线
public class App {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("spring-idol.xml");
System.out.println();
Thinker volunteer = (Thinker)context.getBean("volunteer");
volunteer.thinkOfSomething("This is what I'm thinking");
}
}
>没有Eorr
>没有例外
> @Pointcut中的包是正确的(执行(在Magician方面)
>我在Spring config xml中有这两个项目
<context:component-scan base-package="com.underdogdevs.myspringaspectj" />
<aop:aspectj-autoproxy />
The problem is the
@Before
from theMagician
aspect isn’t printing as it should. Am I missing something here? Why is it not printing? I have other aspect methods that take no arguments and run just fine. Am I not passing the parameter value correctly?
解决方法:
试试这个
@Configuration
public class BeanConfig {
@Bean
public Magician magician() {
return new Magician();
}
...
我不知道它是否在Spring的文档中,但很明显,当Spring分析返回类型的魔术师()时,它是MindReader Spring时无法看到任何注释.
内容总结
以上是互联网集市为您收集整理的java – 为什么这个Spring Aspect不能像方法参数一样打印?全部内容,希望文章能够帮你解决java – 为什么这个Spring Aspect不能像方法参数一样打印?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。