the method of my aspectj pattern doesn't work

I have to log in my controllers which user is performing the operation. Instead of writing a log message in each method of each controller. I think about doing it with aspectj.

I have a package com.bbvaglobalnet.manager.controller wich contains the controllers and i want the log message to be output in all the public methods of the classes of this package and subpackages. So watching the section 6.2.3.4 of

Spring aspect oriented programming

i think my expression is this

execution(public * com.bbvaglobalnet.manager.controller...(..))

My aspect class is the following

package com.bbvaglobalnet.manager.aspects;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import com.bbvaglobalnet.manager.controller.*;

@Aspect
@Component
public class LogUserAspect {

private final static Logger LOGGER = LoggerFactory.getLogger(LogUserAspect.class); 

@Before("execution(public * com.bbvaglobalnet.manager.controller..*.*(..))") 
public void logUser2(JoinPoint jp) {

    LOGGER.info("[User: {}]", SecurityContextHolder.getContext().getAuthentication().getName());
}

}

i know the bean is registered and i've tried with another different patterns and the class seams to work

my spring aop context configuration

<context:component-scan base-package="com.bbvaglobalnet.manager.aspects" />
<aop:aspectj-autoproxy/>

Sorry for my english, it is not my first language

Upvotes: 1

Views: 387

Answers (1)

4calibr4
4calibr4

Reputation: 31

Why do you want to wrap controllers with proxies? Thats seems to me like reinventing the wheel. As per servlet spec if you want to intercept a call to to your servlet and do some processing of request and/or response you should have a closer look at this

Upvotes: 0

Related Questions