spring-aop

How to: Spring get rid of @Validate for automatic Controller validation?

℡╲_俬逩灬. 提交于 2019-12-03 16:12:10
I know about @Valid annotation to instruct spring to validate for example a Controller argument according to JSR-303 in such this example: @GetMapping("/test") public TestDTO testDTO(@Valid TestDTO testDTO){ return testDTO; } But I would like to be able to configure Spring in some way to enable validation in all my controllers without specify explicitly the @Valid annotation. Is that possible in any way? Some Spring configuration? Making use of AOP?... I have finally came across with a working solution which may be not the optimal from the point of view of Spring configuration (as I said I'm

@Tansactional and @Aspect ordering

落花浮王杯 提交于 2019-12-03 15:04:22
问题 I would like to execute my code just before @Transactional transaction is started. @Aspect @Order(Ordered.HIGHEST_PRECEDENCE) //@Order(Ordered.LOWEST_PRECEDENCE) public class SynchronizerAspect { @Pointcut("execution(public * xxx.xxx.services.*.*(..))") private void anyServiceOperation() { } @Around("anyServiceOperation()") public Object synchronizerAdvice(ProceedingJoinPoint joinPoint) throws Throwable { System.out.println("Synchronizing : " + joinPoint.getSignature().getName()); return

Spring AOP and aspect thread safety for an autowired HTTPServletRequest bean

拜拜、爱过 提交于 2019-12-03 12:25:46
I am using Spring 3 AOP, and I have an aspect that requires access to the HttpServletRequest. It looks something like this: @Aspect public class MyAspect { @Autowired private HttpServletRequest httpServletRequest; public void init() { // Do something once... } @Before("my pointcut here...") private void myMethod() { // I need the httpServletRequest... } @After("my pointcut here...") private void myOtherMethod() { // I need the httpServletRequest... } } And is configured like this: <bean id="myAspect" class="com.some.package.MyAspect" init-method="init" /> Is the init method only called once

How to inject HttpServletRequest into a Spring AOP request (custom scenario)?

本秂侑毒 提交于 2019-12-03 12:03:50
问题 I know the standard way of writing an AOP advice around a controller method and that you can get access to the HttpServletRequest arg, if declared in controller method. But my scenario is that I have a translation service, that is currently session-scoped maintaining the user's locale for translation. I feel this makes the service stateful and also I do not want it to be session-scoped, as I think it is really Singleton. But there are multiple places where the translation service methods are

Spring AOP Pointcut syntax for AND, OR and NOT

房东的猫 提交于 2019-12-03 10:57:40
I'm having trouble with a pointcut definition in Spring (version 2.5.6). I'm trying to intercept all method calls to a class, except for a given method (someMethod in the example below). <aop:config> <aop:advisor pointcut="execution(* x.y.z.ClassName.*(..)) AND NOT execution(* x.y.x.ClassName.someMethod(..))" /> </aop:config> However, the interceptor is invoked for someMethod as well. Then I tried this: <aop:config> <aop:advisor pointcut="execution(* x.y.z.ClassName.(* AND NOT someMethod)(..)) )" /> </aop:config> But this does not compile as it is not valid syntax (I get a

How-to configure Spring Social via XML

让人想犯罪 __ 提交于 2019-12-03 09:47:51
问题 I spend a few hours trying to get Twitter integration to work with Spring Social using the XML configuration approach. All the examples I could find on the web (and on stackoverflow) always use the @Config approach as shown in the samples For whatever reason the bean definition to get an instance to the twitter API throws an AOP exception: Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.twitter': Target type could not be determined at the time of

Do method profiling ( Basic execution time ) With Spring AOP

房东的猫 提交于 2019-12-03 06:57:45
I'm looking for a feature or software, who will allow me to easily profile my method execution time and choose what to profile by package filter. I know, it's profiler 101. I use the TPTP profiler. But I'm not happy with it. To be frank I just don't understand how it works, and when I profile my application (launch the server in profiling mode), it takes forever to do nothing. (well, not what I expect: a simple output of execution time) So I do the profiling myself with system time (add a line at beginning and at ending of methods). It's not so bad. My question is : I want to measure system

Spring aop pointcut expression to access method return type

痴心易碎 提交于 2019-12-03 06:48:31
I have a service interface with many methods, all of which take a Request object and return a Response object. All request objects have a common ancestor and all response objects have a different common ancestor (which has a success flag and a message field). Now I want to have an around aspect that checks permissions etc, performs the service call and returns a Response object with a failure code if anything fails. The problem is: I need to know what type of Response object to create. Is there a pointcut expression that gives me access to the return type? Something like this, perhaps? @Around

Autowired dependency not injected in Aspect in Spring MVC

若如初见. 提交于 2019-12-03 06:18:56
I am not able to @Autowire the Service Layer Instance in Aspect. In Aspect the reference to the @Autowired bean is NULL and it throws NullPointerException . Any help will be much appreciated. I think, I messed up with configuration. Following is my servlet-context.xml : <!-- Activates various annotations to be detected in bean classes --> <context:annotation-config /> <context:spring-configured /> <!-- Scans the classpath of this application for @Components to deploy as beans --> <context:component-scan base-package="xx.yy" /> <!-- an @AspectJ aspect will be interpreted as an aspect by Spring

Spring AOP AfterThrowing vs. Around Advice

不打扰是莪最后的温柔 提交于 2019-12-03 05:47:07
问题 when trying to implement an Aspect, that is responsible for catching and logging a certain type of error, I initially thought this would be possible using the AfterThrowing advice. However it seems that his advice doesn't catch the exception, but just provides an additional entry point to do something with the exception. The only advice which would also catch the exception in question would then be an AroundAdvice - either that or I did something wrong. Can anyone assert that indeed if I want