Spring AOP is not working in with MVC structure

abhijit nag

I am using the following structure but failing but failing to create the proxy call.

In controller-servlet.xml

<context:component-scan base-package="com.controller" />
    <mvc:annotation-driven/>
    <mvc:resources mapping="/static/**" location="/static/" />    
    <mvc:default-servlet-handler/>

In application-context.xml

<context:component-scan base-package="com.common" />
    <context:component-scan base-package="com.dao" />
    <mvc:annotation-driven/>

    <aop:aspectj-autoproxy />   

    <!-- Aspect Bean Definition 
    <bean id="aspectBean" class="com.common.AspectImple" /> -->

Aspect class

package com.common;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AspectImple {


    @Before("execution(* com.controller.JobController.*(..))")
        public void beforeImpl() {
           System.out.println("  Before Done ");
    }

}

Controller class

@Controller
    public class JobController {

        @RequestMapping(method = RequestMethod.GET, value = "/xyz")
        public ModelAndView abc(HttpServletRequest request,
            HttpServletResponse response) {
            ...
            m1(10);
            ...
            }
    }

    public void m1(int i){
        System.out.println(" AOP Done ");
    } 

The AOP is not working and during call of abc(..) & m1(..) method, beforeImpl() is not getting called. Could someone please help me out to solve this problem.

Yugang Zhou

What about move

<context:component-scan base-package="com.dao" />
<mvc:annotation-driven/>

<aop:aspectj-autoproxy />   

from application-context.xml to controller-servlet.xml?

The aspects and the beans to be applied needs to be in the same ApplicationContext but ApplicationContext is not aware of WebApplicationContext .

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring AOP with SPring MVC controllers not working

Pointcut not working with Spring AOP

Spring AOP Annotation not working

Spring AOP: Interceptor not working

Ordering aspects with Spring AOP && MVC

Java - Spring AOP Pointcut not working

Spring-AOP pointcut not working?

correct structure in MVC with spring

Spring 3 MVC @Controller with AOP interceptors?

Spring AOP - aspect not working without xml configuration

Custom Spring AOP Annotation Not Working for Default Method

Logging not working in web application using Spring AOP

Spring + HibernateTemplate + AOP for transaction mamangement not working

Spring aop aspect: using ".." not working to replace parameters?

Bean autowiring not working after Spring AOP

OpenEntityManagerInViewFilter not working - Spring MVC

logout not working in spring mvc

SwaggerSpringMvcPlugin not working on Spring MVC

Spring and MVC proper project structure

Is DAO the same as Model when working in MVC structure?

Java Deserialization issue in SPring MVC Project using AOP

Spring AOP not working for method call inside another method

Spring AOP pointcut for custom annotation not working inner static class

Spring AOP not working, when the method is called internally within a bean

Spring AOP @AfterThrowing not working properly, error at ::0 formal unbound in pointcut

Spring aop multiple pointcuts & advice but only the last one is working

Spring AOP not working when using as a compiled jar in a different project

Spring AOP implementation is not working for my project using @Aspect

Spring boot 2.0.2, interception of Cloud Stream annotations with Aop not working anymore