Reputation: 1
I am trying to use the Around method around my rest controller using a logger class. I get the output "Before calling Controller","After calling controller" etc, but I don't get any return result in my postman.
The code works fine with @Before method and @After.
The ReST Controller looks like this.
@RestController("/")
public class DummyController {
@RequestMapping(value="hello",method=RequestMethod.GET)
public String dummyMethod() {
System.out.println("In Controller...");
return "Hello There";
}
}
This is the Aspect class.
@Aspect
@Component
public class Logger {
@Around("within(DummyController)")//Around Not working....
public void printMessage(ProceedingJoinPoint p) throws Throwable
{
System.out.println("Before Calling Method...");
p.proceed();
System.out.println("After calling method...");
}
The bean configuration is as below:
<mvc:annotation-driven />
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.aop.test"> </context:component-scan>
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</beans>
My output is:
Before Calling Method...
In Controller...
After calling method...
But the webservice output is blank in postman instead of "Hello There". The status is "200 OK"
The code works as expected with other Advices like @Before,@After...
Any pointers on where the code went wrong?
Thanks in Advance..
Upvotes: 0
Views: 774
Reputation: 425
change your Aspect to below and it should work.
@Aspect
@Component
public class Logger {
@Around("within(DummyController)")//Around Not working....
public Object printMessage(ProceedingJoinPoint p) throws Throwable
{
System.out.println("Before Calling Method...");
Object result = p.proceed();
System.out.println("After calling method...");
return result;
}
Notice that I made the advice return the object returned by ProceedingJoinPoint
Upvotes: 1