It helps to have a message listener container
Posted by danielmeyer on December 12, 2008
I couldn’t figure out why the AOP advice kept not running around the MessageListener’s onMessage() method in my integration test. I had declared the MessageListener as a bean (the advice only gets applied to beans) and relaxed the pointcut expression so it shouldn’t have to reside in a certain subpackage; the setup looked good, but still no advice. I ratcheted the logging level up and saw the message being sent, so why wasn’t the advice running? I began to have that piteous, put-upon feeling you get when you think you’re doing everything right but the program is unreasonably refusing to cooperate.
Then I realized that I hadn’t declared a DefaultMessageListenerContainer in my Spring bean file. And then I realized that I had only been seeing messages being sent, never received. (The advice only applies when the message is received). Oops!
I declared the message listener container bean, and messages began to be received with the advice applying as it should. : )