I have a controller class with one RequestMapping method which is taking String arguments. I want to pass this argument by using Spring AOP but its failing, I am getting null value when I am printing the value.
Tried with the below provided solution but its working with map but not with String.
Spring AOP pass argument of a controller method
@Controller
public class WelcomeController {
@Autowired
private FamilyService familyService;
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView welcomePage(String welcomeMessage) {
FamilyVO allFamilyMembers = familyService.getAllFamilyMembers();
ModelAndView modelAndView = new ModelAndView("Index", "family", allFamilyMembers);
List<String> familyMemberAges = new ArrayList<String>();
for (int i = 0; i <= 100; i++) {
familyMemberAges.add("" + i);
}
modelAndView.addObject("familyMemberAges", familyMemberAges);
System.out.println(welcomeMessage);
return modelAndView;
}
}
@Component
@Aspect
public class WelcomeControllerAspect {
@Before("execution(* com.kalavakuri.webmvc.web.controller.WelcomeController.welcomePage(..))")
public void beforeWelcomePage(JoinPoint joinPoint) {
joinPoint.getArgs()[0] = "Hellow";
System.out.println(joinPoint.getArgs().length);
System.out.println("Before welcomepage");
}
}
I am expecting the value "Hello" when I print it in Controller class but printing null.