AnsweredAssumed Answered

Using Java config rather than web.xml in a B2, with servlet 3 environments

Question asked by guy.heatley on Feb 2, 2016
Latest reply on Nov 2, 2016 by guy.heatley


I have been trying to move to Java config rather than use a web.xml in a building block (as the servlet-api that Blackboard uses is version 3 and should support this)

Here's my class that extends the AbstractAnnotationConfigDispatcherServletInitializer which when used produces the strange effect of a nested version of the main page of Blackboard inside the window of the building block with some ajax error.


I suspect the villain is the line in red text, but I'm not sure what to do to fix it. I think the WebApplicationContext gets refreshed needlessly.




import javax.servlet.ServletContext;

import javax.servlet.ServletRegistration;


import org.springframework.web.context.WebApplicationContext;

import org.springframework.web.servlet.DispatcherServlet;





public class UclanAnnotConfDispServInit extends

  AbstractAnnotationConfigDispatcherServletInitializer {



  protected Class<?>[] getRootConfigClasses() {

  // TODO Auto-generated method stub

  return null;




  protected Class<?>[] getServletConfigClasses() {

  return new Class<?>[] { MvcConfiguration.class };




  protected String[] getServletMappings() {

  return new String[] { "/" };




  protected void registerDispatcherServlet(ServletContext servletContext) {


  //servletContext.setInitParameter("defaultHtmlEscape", "true");


  WebApplicationContext servletAppContext = createServletApplicationContext();

  // The main Spring MVC dispatcher servlet will use the MVC context.

  DispatcherServlet ds = new DispatcherServlet(servletAppContext);



  ServletRegistration.Dynamic appServlet = servletContext.addServlet(

  "appServlet", ds);"Dispatcher servlet (called 'appServlet') added.");



  appServlet.setInitParameter("debug", "true");







Here's the web.xml file which works fine (on my dev VM) if I add it into the project and remove the class listed above:


<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" xmlns=""




    <display-name>Spring Demo</display-name>


    <!-- The central dispatcher servlet for the spring side of things -->


























Any ideas on how to make the Java config version behave correctly?


EDIT: Whilst the B2 version that uses the web.xml works OK on my dev VM it too causes the strange "nested frontpage" effect on our test Blackboard installation. If I remove the web.xml file to use the Java config this fails to work properly on any system.