Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:31:21+00:00 2026-06-09T22:31:21+00:00

I have some methods advised by two aspects, one is using the spring AOP

  • 0

I have some methods advised by two aspects, one is using the spring AOP support and the other is a BeanPostProcessor (MethodValidationPostProcessor specifically) which advises all method with @Validation annotation. With my unit tests I am trying to force throwing an error by breaking the method contract, but sometimes the validation is in place (the advise imposed by the above mentioned post processor) and sometimes does not work. Does anybody have experienced something similar.

Here is a small snippet of what I am trying to do:

Aspect code:

@Aspect
@Component
public final class LoggingAspect {
    @Before(value = "execution(public * * (..)) && @annotation(loggable)",
    argNames = "joinPoint, loggable")
    public void before(JoinPoint joinPoint, Loggable loggable) {
         //logging here... 
    }
}

Annotation (Loggable Code)

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Loggable {...}

Interface being annotated with @Validated annotation (Here’s a link with related info).

@Validated
public interface Dao<T, K> {
    T findById(@NotNull K id);
    T persist(@NotNull T object);
}

A base class implementing this interface:
public abstract class BaseDao implements DAO {
@Loggable
public T persist(T object){…}
}

And a subclass with a particular behavior:
public final class UserDao extends BaseDao {
@Loggable
public T findById(User object){…}
}

And the spring context at last something like this

<aop:aspectj-autoproxy/>
<context:annotation-config/>
<context:component-scan base-package="com.my.package"/>
<bean id="validator"
  class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"/>

I am testing by calling both methods with null as the argument, but in some occasions I received an IllegalArgumentException: attempt to create saveOrUpdate event with null entity instead of the MethodConstraintViolationException supposedly raised by the
instead MethodValidationInterceptor which advises/intercepts all public method for @Validated annotated interfaces.

EDIT: I am using spring 3.1, Hibernate Validator 4.2 (as required by spring) and aspectj 1.7.

EDIT 2: I did some more digging around the test code, and I found out there is something strange related to the MethodValidationPostProcessor or the MethodValidationInterceptor. I disabled the aop-autoproxy and remove the LoggerAspect during testing, and still there is some problem that in some occasion the Validation resulted in what I expected and in some other situations where even though it is supposed to fails the MethodValidationInterceptor or the MethodValidator fails to catch the errors in the calls.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:31:22+00:00Added an answer on June 9, 2026 at 10:31 pm

    Digging around I found out the problem was related to where I put the annotations. Sorry for the inconvenience.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Spring 3.0 and ehcache. I have added @Cacheable annotations to some methods
Now I have two .jar files: one is a chat Client and the other
I have some methods that are used by several classes. My idea was to
I have some Visual Basic methods that are acting as the click handlers for
I have a DLL containing some methods (show, hide and validate). Here is an
I have some special parameters to all my wcf service methods that are handled
i have a coldfusion cfc and some methods in it. MethodA will return a
I have a simple Java class that has some methods: public class Utils {
I have an abstract class with some methods,including an abstract method(Execute()).This method is overridden
Just random pick some methods that I have found: sforce.connection.describeSObject sforce.SearchResult sforce.sObject sforce.LeadConvert() sforce.connection.create()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.