aspectj

Spring AspectJ fails when double-proxying interface: Could not generate CGLIB subclass of class

萝らか妹 提交于 2019-12-09 11:38:00
问题 I'm using Spring's <aop:aspectj-autoproxy /> to proxy some JPA repository interfaces. However, the proxying is failing with the following Cannot subclass final class class $Proxy80 : Could not generate CGLIB subclass of class [class $Proxy80]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy80 As the error, and a quick google, suggests - this occurs when the proxy

Can AspectJ replace “new X” with “new SubclassOfX” in third-party library code?

谁说胖子不能爱 提交于 2019-12-09 11:13:57
问题 I am looking at AspectJ to see if perhaps we can use it in our test suite. We have a rather large third party Java communications library hardwired to use its own classes (which do not implement any interfaces) which in turn mean that we need a physical backend present and correctly configured to be able to run tests. I am looking at our options for removing this restriction. A possibility would be to create a subclass of the troublesome classes and then ask AspectJ to simply replace "new X"

Turning one annotation into many annotations with AspectJ

£可爱£侵袭症+ 提交于 2019-12-09 10:58:35
问题 I have discovered a pattern in my JPA mappings that I would like to codify. A simple example follows: @OneToMany(fetch=FetchType.EAGER) @Sort(type=SortType.NATURAL) private SortedSet<Item> items; I would like to create a single annotation called SortedOneToMany that I can apply to the above set: public @interface SortedOneToMany { FetchType fetch() default EAGER; SortType sort() default NATURAL; Class comparator() default void.class; } I have written the following aspect to "attach" the JPA

Maven project not being treated as Java in Eclipse

只谈情不闲聊 提交于 2019-12-09 08:15:57
问题 I'm working on a project that has lots of different Maven projects. I've been doing a bunch of JUnit testing on these projects, and usually this goes well. I open up Eclipse, right click in package explorer->Import... Existing Maven Projects and I'm able to import the project fine. I can build, drill down to src/test/java... Right click on the file and do a Run As JUnit test. Every now and then though, I can't get this to work. If I right click to do a Run As, all I get is AspectJ/Java

Spring AOP 最热门面试题及答案

社会主义新天地 提交于 2019-12-09 02:00:00
译者的话 之前去京东面试,被问到 AOP 相关的问题,之前一直没有系统地学习相关的知识,答得不是很好。趁着假期,找了一下相关的资料,CSDN上有很多不错的文章,看了之后对 AOP 有比较好的理解了。然后 Google 了一下 AOP 相关面试题(AOP interview),搜出来的第一条结果是一个叫 HowToDoInJava 的网站上的一篇文章 Top Spring AOP Interview Questions with Answers 。 看了一下,实话说,写得并不是很简单易懂,只是介绍性的文章而已。但是通篇看下来,基本的知识点也都覆盖到了。文章不是很长,所以为了加深印象,顺便把它翻译出来,以供大家参考。 Spring AOP 最热门面试题及答案 看完 Spring 核心面试题之后 ,让我们来看一下 Spring AOP 面试题,这个你可能会在下一次技术面试的时候遇到。同样的,请尽管提出一些这个帖子相关的新的问题来,我会把它们包含进来,以让更多的读者受益。 内容大纲: 描述一下Spring AOP? 在Spring AOP中关注点(concern)和横切关注点(cross-cutting concern)有什么不同? AOP有哪些可用的实现? Spring中有哪些不同的通知类型(advice types)? Spring AOP 代理是什么? 引介(Introduction

Spring AOP Pointcut expression for annotated field

半世苍凉 提交于 2019-12-08 13:56:27
Is it possible to capture any field with a specific annotation? My end goal is to inject a value into that field, but currently my pointcut is wrong (not sure of the correct syntax). @Pointcut("execution(* *(..)) && @annotation(com.mycompany.MyAnnotation)") private void annotatedField(){} @Around("annotatedField()") public Object injectValue(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {} I believe the pointcut is stating any Method with the annotation. and I want to change that to say any Field. I think you should follow the advice of Sotirios Delimanolis and get as far as

Compile Time Weaving Null Pointer Exception

ⅰ亾dé卋堺 提交于 2019-12-08 10:28:20
问题 Edit 7: The problem seems to be how to get @Configurable working with HttpSessionListener , a workaround is suggested, but I'dd prefer not to to interact with the WebApplicationContext directly: @Configurable(autowire = Autowire.BY_TYPE, preConstruction = true) public class SessionListener implements HttpSessionListener { private static final Logger log; @Autowired private A a; @Override public void sessionCreated(HttpSessionEvent se) { a.doSomething(); // <- Throws NPE log.info("New session

NoClassDefFoundError while running on 64bit machine

早过忘川 提交于 2019-12-08 09:54:40
问题 I am getting the following exception while service startup on a 64bit Machine. But the code runs fine on a 32bit machine. java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader

JavaScript div resizing with aspect ratio

半城伤御伤魂 提交于 2019-12-08 09:54:27
问题 I'm writing a little script that allows the user to move and resize a div. I need to keep the aspect ratio and my logic doesn't work. function resizing() { var currentHeight = elmnt.offsetHeight; var currentWidth = elmnt.offsetWidth; var newHeight = currentHeight + (event.pageY - currentY); var newWidth = currentWidth + (event.pageX - currentX); var ratio = currentWidth / currentHeight; if(ratio < 1) { newwidth = parseInt(newHeight * ratio); } else { newheight = parseInt(newWidth / ratio); }

Spring MVC with AspectJ

喜欢而已 提交于 2019-12-08 07:58:10
问题 I have a working spring mvc project. I want to log each request through my controllers with using AspectJ. The relevant code: The Controller: (in package hu.freetime.controller) @Controller @RequestMapping("/") public class BaseControllerImpl { @RequestMapping(method = RequestMethod.GET) public String index(Model model) { return "index"; } } The Aspect: @Aspect public class ControllerAspectImpl { Logger logger = LoggerFactory.getLogger(ControllerAspectImpl.class); @Pointcut("execution(public