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

  • Home
  • SEARCH
  • 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 7188385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:04:22+00:00 2026-05-28T19:04:22+00:00

I am trying to use Spring AOP with Spring MVC Controller. I have 3

  • 0

I am trying to use Spring AOP with Spring MVC Controller.
I have 3 aspects, and want the to be in specific order. In order to do this, I use Ordered interface and implement getOrder method:

@Aspect
@Component
public class LoggingAspect implements Ordered{

public int getOrder() {
System.out.println("Abra");
return 1;
}

Adviced class:

@Component
@Controller
public class HomeController {   

Pointcuts:

@Aspect
public class SystemArchitecture {

    @Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))")
    public void inHomeController(){}

    @Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))")
    public void loggable(){}

    @Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))")
    public void authenticated(){}

}

Configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"   
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <annotation-driven />
    <context:annotation-config /> 
    <aop:aspectj-autoproxy proxy-target-class="false"/>

    <beans:bean id="AuthenticationAspect" class="com.jajah.CommonAspects.SecurityAspects.OAuthAspect"/>
    <beans:bean id="ErrorHandlingAspect" class="com.jajah.StorageManager.Aspects.ErrorHandlingAspect"/>


    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <!-- <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />

    </beans:bean> -->

    <beans:bean name="homeController" class="com.jajah.StorageManager.HomeController">
        <beans:constructor-arg>     
            <beans:ref bean="CloudStorage"/>
        </beans:constructor-arg>
        <beans:constructor-arg>     
            <beans:ref bean="ConfigurationContainer"/>
        </beans:constructor-arg>
    </beans:bean>

    <beans:bean id="CloudStorage" name="CloudStorage"       class="com.jajah.StorageManager.CloudStorageProxy"      scope="singleton">
        <beans:constructor-arg>     
         <beans:ref bean="ConfigurationContainer"/>
        </beans:constructor-arg>
    </beans:bean>

    <beans:bean id ="ConfigurationContainer" class="com.jajah.StorageManager.ConfigurationContainer" scope="singleton"/>





</beans:beans>

The getOrder doesn’t do the trick.
I will appreciate any practical advice, or if you don’t have the exact answer I will appreciate any theoretical knowledge about the Spring Proxy and the weaving mechanism.

I will post any Code/Configuration required upon demand.
Thanks for reading.

Update:
1. I tried @Order(1) with same result.
2. I tried to move aspects to same package, it changed their order, but I still couldn’t control it.

  • 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-05-28T19:04:23+00:00Added an answer on May 28, 2026 at 7:04 pm

    You don’t need to implement Ordered interface.

    In Spring AOP you can do things much easier.

    @Aspect
    @Order(1)
    public class AspectA
    {
      @Before("............")
       public void doit() {}
    }
    
    @Aspect
    @Order(2)
    public class AspectB
    {
      @Before(".............")
      public void doit() {}
    } 
    

    Update:

    @Aspect
    @Order(1)
    public class SpringAspect {
    
        @Pointcut("within(com.vanilla.service.MyService+)")
        public void businessLogicMethods(){}
    
         @Around("businessLogicMethods()")
         public Object profile(ProceedingJoinPoint pjp) throws Throwable {
                 System.out.println("running Advice #1");   
             Object output = pjp.proceed();
             return output;
         }
    }
    
    @Aspect
    @Order(2)
    public class SpringAspect2 {
    
        @Pointcut("within(com.vanilla.service.MyService+)")
        public void businessLogicMethods(){}
    
         @Around("businessLogicMethods()")
         public Object profile(ProceedingJoinPoint pjp) throws Throwable {
                 System.out.println("running Advice #2");   
             Object output = pjp.proceed();
             return output;
         }
    }
    

    Now the application Context Configuration XML:

    <context:annotation-config />
    <aop:aspectj-autoproxy />
    
      <bean id="springAspect" class="com.vanilla.aspect.SpringAspect" />
        <bean id="springAspect2" class="com.vanilla.aspect.SpringAspect2" />
    

    You need to enable AOP proxy by:

    <aop:aspectj-autoproxy />
    

    otherwise no advice will be activated.

    Update 2:

    I just make a research on this issue. @order annotation works only on Spring’s based proxy AOP (Which I’m using in my example). Accoridng to documentation if you are using weaving you should use declare precedence option.

    Update 3

    1. I don’t see any advices in your code, just aspects and pointcuts.
    2. If your Advice classes are: x.y.z.SystemArchitecture

    then you need to configure it at as

    <bean id="systemArchitecture" class="x.y.z.SystemArchitecture" /> 
    

    and I don’t see it in your code.

    1. “execution (* com.jajah.StorageManager.HomeController.*(..))” what are you targeting on? Can you write it using words?

    Anyway. Please drop me a message on facebook and I’ll send you working example which does exactly what are you trying to do.

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

Sidebar

Related Questions

I'm trying to use Spring IoC with an interface like this: public interface ISimpleService<T>
I have a Spring MVC application trying to use a rich domain model, with
As a newbie in ExtJS I'm trying to use it with Spring MVC Controller.
I am trying to use Spring's @AspectJ compile-time weaving instead of <aop:autoproxy/> and it
I'm trying to use hibernate with spring 3 mvc but at the moment I
HI am starting to use spring 3 mvc and have run into a problem
I want to use spring-aspects to make my methods transactional, but without using Spring
I have been trying to use Spring in my Java EE projects and while
I am trying to use Spring batch and implement an aggregated reader (batch file,
I am trying to use validation with Spring 3.x. I have annotated a method

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.