Just to provide some further clarity into how I resolved this problem, I have chosen to answer my own question.
1. As suggested in DigitalJoel's answer, I created an ApplicationListener
bean. This Listener is fired each time the context is refreshed.
LookupLoader.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.tothought.entities.SkillCategory;
import org.tothought.repositories.SkillCategoryRepository;
public class LookupLoader implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
SkillCategoryRepository repository;
private List<SkillCategory> categories;
public List<SkillCategory> getCategories() {
return categories;
}
public void setCategories(List<SkillCategory> categories) {
this.categories = categories;
}
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if(this.categories == null){
this.setCategories(repository.findAll());
}
}
}
2. Next, I registered this bean in my application configuration.
application-context.xml (Spring-Config)
<bean id="lookupLoader"
class="org.tothought.controllers.initializers.LookupLoader" />
3. Then to place this bean in each request I created a HandlerInterceptorAdapter
that is executed each time a request is received. In this bean I autowired the LookupLoader and set my list in the request.
LookupHandlerInterceptor.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.tothought.controllers.initializers.LookupLoader;
public class LookupHandlerInterceptor extends HandlerInterceptorAdapter {
@Autowired
LookupLoader loader;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
request.setAttribute("skillCategories", loader.getCategories());
return super.preHandle(request, response, handler);
}
}
4. Register the HandlerInterceptor within the Spring MVC web application configuration
servlet-context.xml
<!-- Intercept request to blog to add paging params -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="org.tothought.controllers.interceptors.LookupHandlerInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
5. Access the list via JSP & JSTL
<c:forEach var="category" items="${skillCategories}">
${category.name}
</c:forEach>