Package org.springframework.web.context

Examples of org.springframework.web.context.WebApplicationContext


  public void testSource()
  {
    Class actionBeanClass = TestAction.class;

    ServletContext servletContext = createStrictMock(ServletContext.class);
    WebApplicationContext wac = createStrictMock(WebApplicationContext.class);

    expect(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
        .andReturn(wac);
    expect(wac.isSingleton("beanName")).andReturn(false);
    expect(wac.getBean("beanName", TestAction.class)).andReturn(new TestAction());

    // second call - note that isSingleton is not called second time
    expect(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
        .andReturn(wac);
    expect(wac.getBean("beanName", TestAction.class)).andReturn(new TestAction());

    replay(servletContext);
    replay(wac);

    SpringActionBeanSource source = new SpringActionBeanSource(actionBeanClass, "beanName");
View Full Code Here


  {

    Class actionBeanClass = TestAction.class;

    ServletContext servletContext = createStrictMock(ServletContext.class);
    WebApplicationContext wac = createStrictMock(WebApplicationContext.class);

    expect(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
        .andReturn(wac);
    expect(wac.isSingleton("beanName")).andReturn(false);
    expect(wac.getBean("beanName", TestAction.class)).andThrow(
        new NoSuchBeanDefinitionException("beanName", "message"));

    replay(servletContext);
    replay(wac);
View Full Code Here

    }

    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("Starting FtpServer");  

        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
       
        FtpServer server = (FtpServer) ctx.getBean("myServer");
       
        sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);
       
        try {
            server.start();
View Full Code Here

    public void destroy() throws Exception {
        serialize();
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        WebApplicationContext wac = (WebApplicationContext) applicationContext;
        contextTempDir = (File) wac.getServletContext().getAttribute("javax.servlet.context.tempdir");
    }
View Full Code Here

  }

  public Object createBean(ActionContext context)
  {
    ServletContext servletContext = context.getContext();
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

    synchronized (this)
    {
      if (!checkNotSingleton)
      {
        Assert.isTrue(!wac.isSingleton(beanName), "Spring-registered action bean " + beanName
            + " cannot be a singleton");
        checkNotSingleton = true;
      }
    }

    return wac.getBean(beanName, actionBeanClass);
  }
View Full Code Here

   * Returns named Spring bean from <code>ServletContext</code>. Throws
   * <code>ApplicationConfigurationException</code> if Spring context is not present or named bean is not present in context
   */
  public static Object getSpringBean(ServletContext servletContext, String beanName)
  {
    WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    if (context == null)
    {
      throw new ApplicationConfigurationException(
          "No spring root context found using "
              + "WebApplicationContextUtils.getWebApplicationContext(servletContext). This is probably an application configuration error");
    }

    Object bean = context.getBean(beanName);
    if (bean == null)
    {
      throw new ApplicationConfigurationException("No spring bean " + beanName
          + " found. This is probably an application configuration error");
    }
View Full Code Here

            servletContext = PortletContext.getContext().getServletContext();
        }
       
        if (logger.isDebugEnabled())
            logger.debug("OpenSessionInXWorkInterceptor: " + servletContext);
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

        return (SessionFactory) wac.getBean(getSessionFactoryBeanName());
    }
View Full Code Here

    private static Cipherer cipherer;
    private static Log log = LogFactory.getLog(EncryptedUUIDConverter.class);

    protected void initEncryption() {
        WebContext webCtx = WebContextFactory.get();
        WebApplicationContext springContext = RequestContextUtils.getWebApplicationContext(webCtx.getHttpServletRequest(), webCtx.getServletContext());
        decipherer = (Decipherer) springContext.getBean("cryptographyManager");
        cipherer = (Cipherer) decipherer;
        if (log.isInfoEnabled()) log.info("UUID converter found cipherer/decipherer: " + decipherer.getClass().getName());
    }
View Full Code Here

    private static Cipherer cipherer;
    private static Log log = LogFactory.getLog(EncryptedClassConverter.class);

    protected void initEncryption() {
        WebContext webCtx = WebContextFactory.get();
        WebApplicationContext springContext = RequestContextUtils.getWebApplicationContext(webCtx.getHttpServletRequest(), webCtx.getServletContext());
        decipherer = (Decipherer) springContext.getBean("cryptographyManager");
        cipherer = (Cipherer) decipherer;
        if (log.isInfoEnabled()) log.info("Class converter found cipherer/decipherer: " + decipherer.getClass().getName());
    }
View Full Code Here

    @Before
    public void setup() throws JspException {
        context = new RenderContext();
        service = createNiceMock(RenderService.class);
        scriptManager = createMock(ScriptManager.class);
        WebApplicationContext wContext = createNiceMock(WebApplicationContext.class);
        expect(wContext.getBean(RenderService.class)).andReturn(service).anyTimes();
        expect(wContext.getBean(ScriptManager.class)).andReturn(scriptManager).anyTimes();
        replay(wContext);
        ServletContext servletContext = createNiceMock(ServletContext.class);
        expect(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).andReturn(wContext).anyTimes();
        replay(servletContext);
        ServletRequest request = new MockHttpServletRequest();
View Full Code Here

TOP

Related Classes of org.springframework.web.context.WebApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.