List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext
@Nullable public static WebApplicationContext getWebApplicationContext(ServletContext sc)
From source file:org.atomserver.utils.jetty.StandAloneAtomServer.java
public static void main(String[] args) throws Exception { // the System Property "atomserver.home" defines the home directory for the standalone app String atomserverHome = System.getProperty("atomserver.home"); if (StringUtils.isEmpty(atomserverHome)) { log.error("The variable \"atomserver.home\" must be defined"); System.exit(-1);/*from w w w . j a va 2 s . co m*/ } File atomserverHomeDir = new File(atomserverHome); if (!atomserverHomeDir.exists() && !atomserverHomeDir.isDirectory()) { log.error("The variable \"atomserver.home\" (" + atomserverHome + ") must point to a directory that exists"); } // instantiate the Jetty Server Server server = new Server(); // create a new connector on the declared port, and set it onto the server log.debug("atomserver.port = " + System.getProperty("atomserver.port")); Connector connector = new SelectChannelConnector(); connector.setPort(Integer.getInteger("atomserver.port", DEFAULT_PORT)); server.setConnectors(new Connector[] { connector }); // create a ClassLoader that points at the conf directories log.debug("atomserver.conf.dir = " + System.getProperty("atomserver.conf.dir")); log.debug("atomserver.ops.conf.dir = " + System.getProperty("atomserver.ops.conf.dir")); ClassLoader classLoader = new ConfigurationAwareClassLoader(StandAloneAtomServer.class.getClassLoader()); // load the version from the version.properties file Properties versionProps = new Properties(); versionProps.load(classLoader.getResourceAsStream(DEFAULT_VERSIONS_FILE)); String version = versionProps.getProperty("atomserver.version"); // create a new webapp, rooted at webapps/atomserver-${version}, with the configured // context name String servletContextName = System.getProperty("atomserver.servlet.context"); log.debug("atomserver.servlet.context = " + servletContextName); WebAppContext webapp = new WebAppContext(atomserverHome + "/webapps/atomserver-" + version, "/" + servletContextName); // set the webapp's ClassLoader to be the one that loaded THIS class. the REASON that // this needs to be set is so that when we extract the web application context below we can // cast it to WebApplicationContext here webapp.setClassLoader(StandAloneAtomServer.class.getClassLoader()); // set the Jetty server's webapp and start it server.setHandler(webapp); server.start(); // if the seed system property was set, use the DBSeeder to populate the server String seedDB = System.getProperty("seed.database.with.pets"); log.debug("seed.database.with.pets = " + seedDB); if (!StringUtils.isEmpty(seedDB)) { if (Boolean.valueOf(seedDB)) { Thread.sleep(2000); WebApplicationContext webappContext = WebApplicationContextUtils .getWebApplicationContext(webapp.getServletContext()); DBSeeder.getInstance(webappContext).seedPets(); } } server.join(); }
From source file:com.pamarin.income.util.SpringUtils.java
public static <T> T getBean(Class<T> clazz) { return WebApplicationContextUtils.getWebApplicationContext(FacesUtils.getServletContext()).getBean(clazz); }
From source file:com.pamarin.income.util.SpringUtils.java
public static Object getBean(String bean) { return WebApplicationContextUtils.getWebApplicationContext(FacesUtils.getServletContext()).getBean(bean); }
From source file:com.blogspot.na5cent.orm.util.JSFSpringUtils.java
public static <T> T getBean(ServletContext servletContext, Class<T> clazz) { return WebApplicationContextUtils.getWebApplicationContext(servletContext).getBean(clazz); }
From source file:br.com.jreader.util.ServiceFinder.java
public static Object findBean(String beanName) { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); ServletContext servletContext = (ServletContext) externalContext.getContext(); ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); Object object = applicationContext.getBean(beanName); return object; }
From source file:com.ateam.login.ServiceFinder.java
public static Object findBean(String beanName) { FacesContext context = FacesContext.getCurrentInstance(); ServletContext servletContext = (ServletContext) context.getExternalContext().getContext(); ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); Object o = appContext.getBean(beanName); return o;/* w w w . j ava 2 s . c o m*/ }
From source file:com.blogspot.na5cent.orm.util.JSFSpringUtils.java
public static Object getBean(ServletContext servletContext, String bean) { return WebApplicationContextUtils.getWebApplicationContext(servletContext).getBean(bean); }
From source file:ca.travelagency.utils.AutowiredUtils.java
public static void autowire(ServletContext servletContext, Object existingBean) { WebApplicationContext webApplicationContext = WebApplicationContextUtils .getWebApplicationContext(servletContext); AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext .getAutowireCapableBeanFactory(); autowireCapableBeanFactory.autowireBean(existingBean); }
From source file:darks.grid.spring.GridSpringContext.java
public static boolean loadContext(ServletContext ctx) { context = WebApplicationContextUtils.getWebApplicationContext(ctx); return context != null; }
From source file:org.brekka.paveway.web.support.PolicyHelper.java
public static UploadPolicy identifyPolicy(ServletContext servletContext) { WebApplicationContext webApplicationContext = WebApplicationContextUtils .getWebApplicationContext(servletContext); UploadPolicyService uploadPolicyService = webApplicationContext.getBean(UploadPolicyService.class); return uploadPolicyService.identifyUploadPolicy(); }