List of usage examples for org.springframework.web.context WebApplicationContext getBean
<T> T getBean(String name, Class<T> requiredType) throws BeansException;
From source file:com.autentia.wuija.util.web.jsf.SpringUtils.java
/** * Devuelve un bean sacndolo del ApplicationContext de Spring. El ApplicationContext de Spring lo obtiene gracias * al contexto de JSF. Es obligatorio que ya exista el ApplicationContext, de lo contrario se lanzar una excepcin. * <p>//from w w w . ja v a2 s . co m * La busqueda del bean se hace slo por nombre. * * @param <T> * @param beanName * @param beanClass * @param context * @return */ @SuppressWarnings("unchecked") public static <T> T getBean(FacesContext context, Class<T> beanClass, String beanName) { // XXX [wuija] hacer que si no se encuentra por nombre, se busuqe por tipo final WebApplicationContext wac = FacesContextUtils.getRequiredWebApplicationContext(context); final T bean = (T) wac.getBean(beanName, beanClass); return bean; }
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 {/*from ww w . ja v a2 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:ar.com.zauber.commons.web.uri.UriJspFunctions.java
/** Construye un uri con el bean factory de UriBean. de no ser posible usa el default*/ public static String buildVarArgs(final ServletRequest request, final String uriKey, final String uriBean, final Object... params) { Validate.notNull(uriKey);// ww w . j a v a2s . c om Validate.notNull(uriBean); Validate.notNull(request); UriFactory uFactory = null; try { logger.info("Resolving Urifactory bean."); WebApplicationContext appCtx = RequestContextUtils.getWebApplicationContext(request); try { uFactory = appCtx.getBean(uriBean, UriFactory.class); logger.info("Using {} UriFactory.", uriBean); } catch (NoSuchBeanDefinitionException e) { return buildVarArgs(request, uriKey, params); } } catch (Throwable e) { throw new UnhandledException("inicializando urifactory", e); } return uFactory.buildUri(uriKey, params); }
From source file:ar.com.zauber.commons.web.uri.UriJspFunctions.java
/** Construye un uri */ public static String buildVarArgs(final ServletRequest request, final String uriKey, final Object... params) { Validate.notNull(uriKey);//w w w. j a v a2s . c o m Validate.notNull(request); if (!initialized.getAndSet(true)) { try { logger.info("Resolving Urifactory bean."); WebApplicationContext appCtx = RequestContextUtils.getWebApplicationContext(request); try { uriFactory = appCtx.getBean(SpringBeans.LINK_URIFACTORY_KEY, UriFactory.class); logger.info("Using {} UriFactory.", SpringBeans.LINK_URIFACTORY_KEY); } catch (NoSuchBeanDefinitionException e) { logger.info("Using Default UriFactory."); uriFactory = new RelativePathUriFactory(new IdentityUriFactory()); } } catch (Throwable e) { initialized.set(false); throw new UnhandledException("inicializando urifactory", e); } } return uriFactory.buildUri(uriKey, params); }
From source file:in.anjan.struts2webflow.FlowExecutorUtils.java
/** * {@link FlowExecutor Flow executor} must be configured in the Spring * web application context hierarchy.// w w w . j a v a 2 s.co m * * @param flowExecutorBean {@link FlowExecutor flow executor} bean name to * be used * @return {@link FlowExecutor flow executor} bean * @throws RuntimeException in case {@link FlowExecutor flow executor} is * not configured in the Spring web application * context hierarchy. */ public static FlowExecutor getRequiredFlowExecutor(String flowExecutorBean) { // need to find the Spring web application context WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(ServletActionContext.getServletContext()); // have the flow executor configured? // if yes, get the flow execution // else, blame if (context.containsBean(flowExecutorBean)) return context.getBean(flowExecutorBean, FlowExecutor.class); throw new RuntimeException("Flow executor named as '" + flowExecutorBean + "' not found!"); }
From source file:grails.util.GrailsWebUtil.java
/** * Looks up a GrailsApplication instance from the ServletContext. * * @param servletContext The ServletContext * @return A GrailsApplication or null if there isn't one *//*from ww w . jav a 2s .c om*/ public static GrailsApplication lookupApplication(ServletContext servletContext) { if (servletContext == null) { return null; } final WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); if (context == null || !context.containsBean(GrailsApplication.APPLICATION_ID)) { return null; } return context.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class); }
From source file:au.edu.uq.cmm.paul.queue.QueueFeedServlet.java
protected Provider createProvider() { // Grab the JPA EntityManagerFactory for the QueueAdapter from the services object. WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); EntityManagerFactory emf = ctx.getBean("entityManagerFactory", EntityManagerFactory.class); // Initialize the Abdera infrastructure ... QueueFeedAdapter ca = new QueueFeedAdapter(emf); ca.setHref("queue"); SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo(); wi.setTitle("Ingestion Queue Workspace"); wi.addCollection(ca);//w ww . j a v a 2 s .c o m DefaultProvider provider = new DefaultProvider("/atom/"); provider.addWorkspace(wi); provider.init(getAbdera(), null); return provider; }
From source file:no.dusken.aranea.filter.PluginAwareConf.java
public PluginAwareConf(ServletContext context, InputStream inputStream, String fileName, String systemId) { super(context, inputStream, fileName, systemId); WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(context); pluginManager = webApplicationContext.getBean(araneaPluginManagerName, PluginManager.class); addPluginRules(context);//from w w w . java 2 s. co m }
From source file:cs544.wamp_blog_engine.filters.MyFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { WebApplicationContext context = WebApplicationContextUtils .getWebApplicationContext(filterConfig.getServletContext()); userService = context.getBean("userService", IUserService.class); }
From source file:net.mlw.vlh.web.ValueListHandlerTilesAction.java
/** * @see org.apache.struts.tiles.Controller#perform(org.apache.struts.tiles.ComponentContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext) *//*from w ww . j a v a 2 s .c o m*/ public void perform(ComponentContext componentContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) throws ServletException, IOException { String name = (String) componentContext.getAttribute(VALUE_LIST_NAME); String requestName = (String) componentContext.getAttribute(VALUE_LIST_REQUEST_NAME); WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); ValueListHandler vlh = (ValueListHandler) context.getBean("valueListHandler", ValueListHandler.class); ValueListInfo info = ValueListRequestUtil.buildValueListInfo(request); ValueList valueList = vlh.getValueList(name, info); request.setAttribute(requestName, valueList); }