Example usage for org.springframework.web.context ContextLoader getCurrentWebApplicationContext

List of usage examples for org.springframework.web.context ContextLoader getCurrentWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context ContextLoader getCurrentWebApplicationContext.

Prototype

@Nullable
public static WebApplicationContext getCurrentWebApplicationContext() 

Source Link

Document

Obtain the Spring root web application context for the current thread (i.e.

Usage

From source file:fr.mby.opa.osgi.service.OsgiPortalServiceLocator.java

public static WebApplicationContext retrieveWebApplicationContext() {
    final WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();

    Assert.notNull(wac, "WebApplicationContext not initialized yet !");

    return wac;//from   ww  w.j  a  v a2s .c  o m
}

From source file:com.sap.data.db.dao.HibernateUtil.java

private static Configuration configuration(String firstLoad) {
    Configuration configuration = threadLocal.get();
    if (null == configuration || "x".equalsIgnoreCase(firstLoad)) {
        if ("true".equals(PropertyUtil.getWebApplication())) {
            WebApplicationContext webAppCtx = ContextLoader.getCurrentWebApplicationContext();
            LocalSessionFactoryBean sfb = (LocalSessionFactoryBean) webAppCtx.getBean("&sessionFactory",
                    LocalSessionFactoryBean.class);
            configuration = sfb.getConfiguration();
        } else {/* w w  w. ja  va2  s .c o m*/
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                    PropertyUtil.getSpringAppContext());
            LocalSessionFactoryBean localSessionFactoryBean = context.getBean("&sessionFactory",
                    LocalSessionFactoryBean.class);
            configuration = localSessionFactoryBean.getConfiguration();
        }
    }
    threadLocal.set(configuration);
    return configuration;
}

From source file:org.logger.event.web.service.RequestSupport.java

public static RequestSupport getSessionContext() {
    return (RequestSupport) ContextLoader.getCurrentWebApplicationContext().getBean("requestSupport");
}

From source file:com.extjs.djn.spring.loader.SpringLoaderHelper.java

/**
 * Allow to autowired a non spring instanciated object
 * //from   w  ww .j  a  v a  2s .  c om
 * @param objToLoad
 * @param prefixBeanName
 */
public static void autowireBean(Object objToLoad, String prefixBeanName) {
    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) ContextLoader
            .getCurrentWebApplicationContext().getAutowireCapableBeanFactory();
    beanFactory.autowireBeanProperties(objToLoad, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    beanFactory.initializeBean(objToLoad, prefixBeanName);
}

From source file:org.motrice.bpm.hippo.util.ServletUserNameUtil.java

private static void checkEngine() {
    if (engine == null) {
        ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
        engine = (TaskFormService) ctx.getBean("engine");
    }//w w w  .  j a  v  a2s. c o  m
}

From source file:com.dynamobi.ws.util.DB.java

public static Connection getConnection() throws SQLException {

    //DataSource myDataSource;
    WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
    DBSessionHolder dsh = (DBSessionHolder) wac.getBean("sessionConnection");

    return dsh.getSessionConnection();

}

From source file:org.jminix.server.WebSpringServerConnectionProvider.java

public WebSpringServerConnectionProvider() {
    setBeanFactory(ContextLoader.getCurrentWebApplicationContext());
    setServerBeanNames(new String[] { "mbeanServer" });
}

From source file:com.jp.systemdirector.projectzero.zab01.db.dao.ConnectionUtilForSpring.java

/**
 * <p>Connection ??</p>// w ww  .  j  a  v a 2s  .  com
 * @return Connection 
 * @throws SQLException 
 */
public Connection getConnection() throws SQLException {
    // ApplicationContext?dataSource?
    ApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    dataSource = (DataSource) context.getBean("dataSource");
    conn = DataSourceUtils.getConnection(dataSource);
    return conn;
}

From source file:com.dynamobi.ws.util.DB.java

public static void releaseConnection() {
    WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
    DBSessionHolder dsh = (DBSessionHolder) wac.getBean("sessionConnection");
    dsh.releaseSessionConnection();/*w  w  w. j  a v  a 2s .  c  o  m*/
}

From source file:com.ineunet.knife.upload.WebPaths.java

/**
 * @return e.g. /Workspace/iNeunet/ioo/src/main/webapp
 *//*from ww  w.j av a 2  s  . c om*/
public static String getRootPath() {
    if (rootPath == null) {
        WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
        if (webApplicationContext == null) {
            rootPath = System.getProperty(WebUtils.DEFAULT_WEB_APP_ROOT_KEY);
        } else {
            ServletContext servletContext = webApplicationContext.getServletContext();
            rootPath = servletContext.getRealPath("/");
        }
    }
    return rootPath;
}