I downloaded an example of a project that uses HandlerInterceptor for this. Here's what I came up with...
I added this to dispatcher-servlet.xml.
Code:
<bean id="sessionBeanInserter" class="net.sandbox.handlerinterceptors.SessionBeanInserter" />
Here's my net.sandbox.handlerinterceptors.SessionBeanInserte r.
Code:
public class SessionBeanInserter extends HandlerInterceptorAdapter {
@Autowired
private MySessionScopedBean mySessionScopedBean;
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
// Insert the session-scoped bean
modelAndView.addObject("mySessionScopedBean", mySessionScopedBean);
}
}
This results in a server error. The exception is as follows:
Code:
javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
...
Root cause:
Code:
java.lang.NoClassDefFoundError: javax/portlet/PortletRequest
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:2406)
...
What am I doing wrong?