I am using Spring 3.2 with Apache Tiles. I generated a lot of my service classes using Roo. I am trying a simple procedure where I inject a variable into the jsp templates. That part works fine, but I am stuck at the point where I need to reference a service bean.
@Component
public class CustomViewPreparer implements ViewPreparer {
@Autowired
UserProfileService ups;
@Override
public void execute(TilesRequestContext tilesContext,
AttributeContext attributeContext) {
Authentication a = SecurityContextHolder.getContext().getAuthentication();
String name = a.getName(); //get logged in username
UserProfile up = ups.findByUsername(name);
//request.setAttribute("isLoggedIn", up!=null);
}
}
The UserProfileService "ups" is always null. I found this: http://forum.springsource.org/showthread.php?48950-ViewPreparer-is-triggered-before-Session-starts
But I don't understand the response. I can work around this by injecting my variable everytime I return a View, but I am curious how others have solved this problem.