Pessoal, eu estou tentando implementar uma solução usando Spring 3 + JMS(ActiveMQ) + AOP(AspectJ) sem sucesso, os meus aspectos retornam uma mensagem do tipo Exception in thread “main” java.lang.ClassCastException: $Proxy11 cannot be cast to [minha_classe].
O mais importante para mim é justamente fazer o Aspecto funcionar com o Spring, mas até agora nda…
Segue abaixo o xml usado pelo Spring
<?xml version="1.0" encoding="ISO-8859-1"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
">
<context:property-placeholder location="jms.properties"/>
<context:component-scan base-package="br.com.teste.message"/>
<context:component-scan base-package="br.com.teste.configuration"/>
<context:component-scan base-package="br.com.teste.aspect"/>
<aop:aspectj-autoproxy/>
</beans>
A classe Producer que envia a msg para o ActiveMQ por JMS
@Component
public class Producer implements MessageCreator {
@Value("${jms.queue}")
private String customerDestination;
@Autowired
private JmsTemplate jmsTemplate;
public void send() throws Exception {
this.jmsTemplate.send(this.customerDestination, this);
}
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "context.xml" });
Producer p = (Producer) context.getBean("producer");
p.send();
}
public Message createMessage(Session session) throws JMSException {
MapMessage mapMessage = session.createMapMessage();
mapMessage.setLong("id", 2L);
mapMessage.setString("firstName", "Ivan");
mapMessage.setString("lastName", "Junior");
mapMessage.setString("email", "ivan.rodrigues@mail.com.br");
return mapMessage;
}
E aqui o Aspecto para fazer o logging
@Component
@Aspect
public class Logging {
private Logger log = Logger.getLogger(Logging.class);
@After("execution(* *.*(..))")
public void logMessage(){
log.info("Operation realized!");
}
}