List of usage examples for org.springframework.web.context ContextLoader getCurrentWebApplicationContext
@Nullable public static WebApplicationContext getCurrentWebApplicationContext()
From source file:com.github.clboettcher.bonappetit.server.jersey.ServerApplication.java
public ServerApplication() { LOGGER.info(String.format("Initializing Jersey application.")); final WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); register(ctx.getBean(HeartbeatService.class)); }
From source file:org.fcrepo.http.commons.api.rdf.SpringContextAwareIdentifierTranslator.java
protected ApplicationContext getApplicationContext() { return ContextLoader.getCurrentWebApplicationContext(); }
From source file:util.ServerAppConfig.java
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); if (wac == null) { throw new IllegalStateException("Failed to find WebApplicationContext. " + "Was org.springframework.web.context.ContextLoader used to load the WebApplicationContext?"); }/*from w w w .j a v a2 s. co m*/ Map<String, T> beans = wac.getBeansOfType(endpointClass); if (beans.isEmpty()) { // Initialize a new bean instance return wac.getAutowireCapableBeanFactory().createBean(endpointClass); } if (beans.size() == 1) { // Return the matching bean instance return beans.values().iterator().next(); } else { // This should never happen (@ServerEndpoint has a single path mapping) .. throw new IllegalStateException("Found more than one matching beans of type " + endpointClass); } }
From source file:org.motrice.bpm.hippo.components.MotriceBaseComponent.java
public MotriceBaseComponent() { ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); engine = (TaskFormService) ctx.getBean("engine"); }
From source file:com.extjs.djn.spring.loader.SpringLoaderHelper.java
@SuppressWarnings("unchecked") public static Map<String, Object> getBeansOfType(Class<?> instanceClass) { return ContextLoader.getCurrentWebApplicationContext().getBeansOfType(instanceClass); }
From source file:com.dynamobi.ws.util.DBSessionHolder.java
public synchronized Connection getSessionConnection() { while (busy_session) { try {/*from w ww .java 2 s .c o m*/ Thread.sleep(300); } catch (InterruptedException e) { // request could have been terminated, ignore. e.printStackTrace(); } } busy_session = true; final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); UserToDataSource ds = (UserToDataSource) wac.getBean("myDataSource"); boolean badConnection = false; try { if (sessionConnection != null) { badConnection = (sessionConnection.isClosed() || sessionConnection.isReadOnly() || !sessionConnection.isValid(5)); } } catch (java.sql.SQLException e) { badConnection = true; } if (sessionConnection == null || auth.getName() != ds.getUsername() || auth.getCredentials().toString() != ds.getPassword() || badConnection) { try { if (sessionConnection != null) { sessionConnection.close(); } System.out.println("Session Init"); ds.setUsername(auth.getName()); ds.setPassword(auth.getCredentials().toString()); sessionConnection = ds.getConnection(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return sessionConnection; }
From source file:org.solmix.wmix.web.context.WmixContextLoaderListener.java
@Override public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); servletContext = event.getServletContext(); String root = servletContext.getRealPath("/"); if (LOG.isInfoEnabled()) { LOG.info("Initial Web context,used path:" + root + " As [solmix.base]"); }//from w w w . j a v a 2 s .co m System.setProperty("solmix.base", root); WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext(); if (context == null) { String msg = "Can't found spring WebApplicationContext"; servletContext.log(msg); throw new IllegalStateException(msg); } SpringContainerFactory factory = new SpringContainerFactory(context); Container c = factory.createContainer(); ContainerFactory.setThreadDefaultContainer(c); servletContext.setAttribute(CONTAINER_KEY, c); }
From source file:nz.co.senanque.vaadinsupport.application.SpringApplicationLoader.java
public static ApplicationContext loadContext(Application application, HttpServletRequest request) { // Logging// www. j a v a 2s. co m log.info("loading application context for Vaadin application " + application.getClass().getSimpleName()); CURRENT_APPLICATION.set(application); // Find the application context associated with the servlet; it will be the parent ServletContext servletContext; try { // getServletContext() is a servlet AIP 3.0 method, so don't freak out if it's not there servletContext = (ServletContext) HttpServletRequest.class.getMethod("getServletContext") .invoke(request); } catch (Exception e) { servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext(); } WebApplicationContext parent = WebApplicationContextUtils.getWebApplicationContext(servletContext); // Create and configure a new application context for this Application instance ConfigurableWebApplicationContext context = new XmlWebApplicationContext(); context.setId( ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContext.getContextPath() + "/" + application.getClass().getSimpleName() + "-" + UNIQUE_INDEX.incrementAndGet()); context.setParent(parent); context.setServletContext(servletContext); //context.setServletConfig(??); context.setNamespace(application.getClass().getSimpleName()); // Refresh context context.refresh(); CURRENT_APPLICATION.set(null); return context; }
From source file:org.pentaho.pat.server.servlet.AbstractServlet.java
@Override public void init() throws ServletException { super.init(); if (!initDone) { if (!standaloneMode) { applicationContext = ContextLoader.getCurrentWebApplicationContext(); }/*from w w w .j av a 2 s . c o m*/ if (applicationContext == null) { LOG.info(Messages.getString("Servlet.AbstractServlet.StandAlone")); //$NON-NLS-1$ // This happens if we launch PAT without a web context, like in the // GWT shell for example. We'll initialize the context manually. // applicationContext = new FileSystemXmlApplicationContext(contextFiles); applicationContext = new ClassPathXmlApplicationContext("pat-applicationContext.xml"); //$NON-NLS-1$ standaloneMode = true; initSecurityTokens(); } initDone = true; } }
From source file:com.roncoo.controller.BaseController.java
protected ServletContext getServletContext() { return ContextLoader.getCurrentWebApplicationContext().getServletContext(); }