estou tentando usar essa combinação, o log4j está funcionando mas o AOP não está chamando a função para logar!
o que tem de errado no meu código ou está faltando?
a aplicação executa com sucesso mais sem fazer os logs …
aop.AuditLogProcessor.java
package aop;
import org.apache.log4j.Logger;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class AuditLogProcessor
{
private static Logger log = Logger.getLogger(AuditLogProcessor.class);
@After("execution(* aop.GreetingService.sayGreeting())")
public void after() {
log.info("==> after");
}
@After("execution(* aop.GreetingService.sayGreeting())")
public void before() {
log.info("==> before");
}
}
aop.GreetingService.java
package aop;
public class GreetingService {
private String greeting;
GreetingService() {}
GreetingService(String greeting) {
setGreeting(greeting);
}
public void sayGreeting() {
System.out.println( greeting );
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
aop.HelloApp.java
package aop;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class HelloApp {
public static void main(String args[]) {
BeanFactory factory =
new XmlBeanFactory(
new FileSystemResource("aop/spring.xml") );
GreetingService greetingServiceImpl = (GreetingService) factory.getBean("GreetingService");
greetingServiceImpl.sayGreeting();
}
}
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="AuditLogProcessor" class="aop.AuditLogProcessor" />
<bean id="GreetingService" class="aop.GreetingService">
<property name="greeting">
<value>Teste de AOP-Spring!</value>
</property>
</bean>
<aop:aspectj-autoproxy>
<aop:include name="GreetingService"/>
</aop:aspectj-autoproxy>
</beans>
log4j.properties
log4j.rootLogger=INFO, stdout, logfile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=springapp.log
log4j.appender.logfile.MaxFileSize=512KB
log4j.appender.logfile.MaxBackupIndex=3
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
se alguem conseguir me ajudar eu agradeceria!