コード例 #1
0
  /**
   * 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();
  }
コード例 #2
0
  /**
   * 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;
  }
コード例 #3
0
ファイル: LoginAction.java プロジェクト: gtu001/gtu-test-code
 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;
 }
コード例 #4
0
ファイル: Start.java プロジェクト: newtonik/preppa
 public String getSpringBeans() {
   return InternalUtils.join(Arrays.asList(context.getBeanDefinitionNames()));
 }