@Bean
 public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
   MessageDispatcherServlet servlet = new MessageDispatcherServlet();
   servlet.setApplicationContext(applicationContext);
   servlet.setTransformWsdlLocations(false);
   return new ServletRegistrationBean(servlet, Constants.SERVLET_REGISTRATION_BEAN);
 }
Esempio n. 2
0
  @Override
  public void onStartup(final ServletContext servletContext) throws ServletException {
    try {
      // Force the timezone of application to UTC (required for
      // Hibernate/JDBC)
      TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

      final Context initialContext = new InitialContext();

      final String logLocation =
          (String)
              initialContext.lookup("java:comp/env/osp/osgpAdapterWsPublicLighting/log-config");
      LogbackConfigurer.initLogging(logLocation);

      final AnnotationConfigWebApplicationContext rootContext =
          new AnnotationConfigWebApplicationContext();
      rootContext.register(ApplicationContext.class);

      servletContext.addListener(new ContextLoaderListener(rootContext));

      final MessageDispatcherServlet servlet = new MessageDispatcherServlet();
      servlet.setContextClass(AnnotationConfigWebApplicationContext.class);
      servlet.setTransformWsdlLocations(true);

      final ServletRegistration.Dynamic dispatcher =
          servletContext.addServlet(DISPATCHER_SERVLET_NAME, servlet);
      dispatcher.setLoadOnStartup(1);
      dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);
    } catch (final NamingException e) {
      throw new ServletException("naming exception", e);
    } catch (final FileNotFoundException e) {
      throw new ServletException("Logging file not found", e);
    } catch (final JoranException e) {
      throw new ServletException("Logback exception", e);
    }
  }