/**
   * Get the application class from the bean configured in Spring's context.
   *
   * @see AbstractApplicationServlet#getApplicationClass()
   */
  @Override
  protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {

    WebApplicationContext wac =
        WebApplicationContextUtils.getWebApplicationContext(getServletContext());

    if (wac == null) {
      throw new ClassNotFoundException(
          "Cannot get an handle on Spring's context. Is Spring running? "
              + "Check there's an org.springframework.web.context.ContextLoaderListener configured.");
    }
    String[] beanDefinitionNames = wac.getBeanDefinitionNames();
    for (String string : beanDefinitionNames) {
      System.out.println("SpringApplicationServlet.getApplicationClass() " + string);
    }

    Application bean = wac.getBean(name, Application.class);

    if (bean == null) {

      throw new ClassNotFoundException("No application bean found under name " + name);
    }

    return bean.getClass();
  }
  /**
   * Get the application bean in Spring's context.
   *
   * @see AbstractApplicationServlet#getNewApplication(HttpServletRequest)
   */
  @Override
  protected Application getNewApplication(HttpServletRequest request) throws ServletException {

    WebApplicationContext wac =
        WebApplicationContextUtils.getWebApplicationContext(getServletContext());

    if (wac == null) {
      throw new ServletException(
          "Cannot get an handle on Spring's context. Is Spring running?"
              + "Check there's an org.springframework.web.context.ContextLoaderListener configured.");
    }

    String[] beanDefinitionNames = wac.getBeanDefinitionNames();
    for (String string : beanDefinitionNames) {
      System.out.println("SpringApplicationServlet.getNewApplication() ->" + string);
    }

    Application bean = wac.getBean(name, Application.class);

    if (!(bean instanceof Application)) {

      throw new ServletException("Bean " + name + " is not of expected class Application");
    }

    return bean;
  }
Ejemplo n.º 3
0
 private WebApplicationContext getContext() {
   WebApplicationContext context =
       WebApplicationContextUtils.getRequiredWebApplicationContext(
           ServletActionContext.getServletContext());
   for (int ii = 0; ii < context.getBeanDefinitionCount(); ii++) {
     logger.debug("bean - " + context.getBeanDefinitionNames()[ii]);
   }
   return context;
 }
Ejemplo n.º 4
0
 public String getSpringBeans() {
   return InternalUtils.join(Arrays.asList(context.getBeanDefinitionNames()));
 }