List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory autowireBeanProperties
void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck) throws BeansException;
From source file:org.intellij.plugins.beans.PluginBeanFactory.java
public void autowireBean(Object bean) { ConfigurableListableBeanFactory factory = getContext().getFactory(); factory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); }
From source file:com.epam.ta.reportportal.auth.PermissionsRegisterBean.java
@SuppressWarnings("unchecked") @Override/*from www. j a v a2 s. c o m*/ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Map<String, Permission> permissionBeans = beanFactory.getBeansOfType(Permission.class); Map<String, Permission> permissionsMap = beanFactory.getBean("permissionsMap", Map.class); for (Entry<String, Permission> permission : permissionBeans.entrySet()) { /* * There will be no NPE since we asked bean factory to get beans * with this annotation */ for (String permissionName : permission.getValue().getClass().getAnnotation(LookupPermission.class) .value()) { /* * TODO add check for type before doing this */ Permission permissionBean = permission.getValue(); beanFactory.autowireBeanProperties(permissionBean, AutowireCapableBeanFactory.AUTOWIRE_NO, true); permissionsMap.put(permissionName, permissionBean); } } }
From source file:org.projectforge.web.meb.SMSReceiverServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { log.debug("Start doPost"); // https://projectforge.micromata.de/secure/SMSReceiver?key=<key>&date=20101105171233&sender=01701891142&msg=Hallo... req.setCharacterEncoding("UTF-8"); final String key = req.getParameter("key"); final String expectedKey = ConfigXml.getInstance().getReceiveSmsKey(); if (StringUtils.isBlank(expectedKey) == true) { log.warn(/*from ww w. j a v a 2 s.com*/ "Servlet call for receiving sms ignored because receiveSmsKey is not given in config.xml file."); response(resp, "NOT YET CONFIGURED"); return; } if (expectedKey.equals(key) == false) { log.warn("Servlet call for receiving sms ignored because receiveSmsKey does not match given key: " + key); response(resp, "DENIED"); return; } final String dateString = req.getParameter("date"); if (StringUtils.isBlank(dateString) == true) { log.warn("Servlet call for receiving sms ignored because parameter 'date' is not given."); response(resp, "Missing parameter 'date'."); return; } final String sender = req.getParameter("sender"); if (StringUtils.isBlank(sender) == true) { log.warn("Servlet call for receiving sms ignored because parameter 'sender' is not given."); response(resp, "Missing parameter 'sender'."); return; } final String msg = req.getParameter("msg"); if (StringUtils.isBlank(msg) == true) { log.warn("Servlet call for receiving sms ignored because parameter 'msg' is not given."); response(resp, "Missing parameter 'msg'."); return; } final Date date = MebDao.parseDate(dateString); if (date == null) { log.warn("Servlet call for receiving sms ignored because couln't parse parameter 'date'."); response(resp, "Unsupported date format."); return; } final ConfigurableListableBeanFactory beanFactory = Configuration.getInstance().getBeanFactory(); beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); MebEntryDO entry = new MebEntryDO(); entry.setDate(date); entry.setSender(sender); entry.setMessage(msg); log.info("Servlet-call: date=[" + date + "], sender=[" + sender + "]"); mebDao.checkAndAddEntry(entry, "SERVLET"); response(resp, "OK"); }
From source file:org.projectforge.web.wicket.WicketApplication.java
@Override protected void init() { super.init(); // Own error page for deployment mode and UserException and AccessException. getRequestCycleListeners().add(new AbstractRequestCycleListener() { /**//from www . j a v a 2s . c o m * Log only non ProjectForge exceptions. * @see org.apache.wicket.request.cycle.AbstractRequestCycleListener#onException(org.apache.wicket.request.cycle.RequestCycle, * java.lang.Exception) */ @Override public IRequestHandler onException(final RequestCycle cycle, final Exception ex) { // in case of expired session, please redirect to home page if (ex instanceof PageExpiredException) { return new RenderPageRequestHandler(new PageProvider(getHomePage())); } final Throwable rootCause = ExceptionHelper.getRootCause(ex); // log.error(rootCause.getMessage(), ex); // if (rootCause instanceof ProjectForgeException == false) { // return super.onException(cycle, ex); // } // return null; if (isDevelopmentSystem() == true) { log.error(ex.getMessage(), ex); if (rootCause instanceof SQLException) { SQLException next = (SQLException) rootCause; while ((next = next.getNextException()) != null) { log.error(next.getMessage(), next); } } return super.onException(cycle, ex); } else { // Show always this error page in production mode: return new RenderPageRequestHandler(new PageProvider(new ErrorPage(ex))); } } }); getApplicationSettings().setDefaultMaximumUploadSize(Bytes.megabytes(100)); getMarkupSettings().setDefaultMarkupEncoding("utf-8"); final MyAuthorizationStrategy authStrategy = new MyAuthorizationStrategy(); getSecuritySettings().setAuthorizationStrategy(authStrategy); getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy); // Prepend the resource bundle for overwriting some Wicket default localizations (such as StringValidator.*) getResourceSettings().getStringResourceLoaders().add(new BundleStringResourceLoader(RESOURCE_BUNDLE_NAME)); getResourceSettings().setThrowExceptionOnMissingResource(false); // Don't throw MissingResourceException for missing i18n keys. getApplicationSettings().setPageExpiredErrorPage(PageExpiredPage.class); // Don't show expired page. // getSessionSettings().setMaxPageMaps(20); // Map up to 20 pages per session (default is 5). getComponentInstantiationListeners().add(new SpringComponentInjector(this)); getApplicationSettings().setInternalErrorPage(ErrorPage.class); // getRequestCycleSettings().setGatherExtendedBrowserInfo(true); // For getting browser width and height. // Select2: // final ApplicationSettings select2Settings = ApplicationSettings.get(); // select2Settings.setIncludeJavascript(false); final XmlWebApplicationContext webApplicationContext = (XmlWebApplicationContext) WebApplicationContextUtils .getWebApplicationContext(getServletContext()); final ConfigurableListableBeanFactory beanFactory = webApplicationContext.getBeanFactory(); beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); final LocalSessionFactoryBean localSessionFactoryBean = (LocalSessionFactoryBean) beanFactory .getBean("&sessionFactory"); // if ("true".equals(System.getProperty(SYSTEM_PROPERTY_HSQLDB_18_UPDATE)) == true) { // try { // log.info("Send SHUTDOWN COMPACT to upgrade data-base version:"); // final DataSource dataSource = (DataSource)beanFactory.getBean("dataSource"); // dataSource.getConnection().createStatement().execute("SHUTDOWN COMPACT"); // log.fatal("************ PLEASE RESTART APPLICATION NOW FOR PROPER INSTALLATION !!!!!!!!!!!!!! ************"); // return; // } catch (final SQLException ex) { // log.fatal("Data-base SHUTDOWN COMPACT failed: " + ex.getMessage()); // } // } final org.hibernate.cfg.Configuration hibernateConfiguration = localSessionFactoryBean.getConfiguration(); HibernateUtils.setConfiguration(hibernateConfiguration); final ServletContext servletContext = getServletContext(); final String configContextPath = configXml.getServletContextPath(); String contextPath; if (StringUtils.isBlank(configContextPath) == true) { contextPath = servletContext.getContextPath(); configXml.setServletContextPath(contextPath); } else { contextPath = configContextPath; } log.info("Using servlet context path: " + contextPath); if (configuration.getBeanFactory() == null) { configuration.setBeanFactory(beanFactory); } configuration.setConfigurationDao(configurationDao); SystemInfoCache.internalInitialize(systemInfoCache); WicketUtils.setContextPath(contextPath); UserFilter.initialize(userDao, contextPath); if (this.wicketApplicationFilter != null) { this.wicketApplicationFilter.setApplication(this); } else { throw new RuntimeException("this.wicketApplicationFilter is null"); } daoRegistry.init(); final PluginsRegistry pluginsRegistry = PluginsRegistry.instance(); pluginsRegistry.set(beanFactory, getResourceSettings()); pluginsRegistry.set(systemUpdater); pluginsRegistry.initialize(); for (final Map.Entry<String, Class<? extends WebPage>> mountPage : WebRegistry.instance().getMountPages() .entrySet()) { final String path = mountPage.getKey(); final Class<? extends WebPage> pageClass = mountPage.getValue(); mountPage(path, pageClass); mountedPages.put(pageClass, path); } if (isDevelopmentSystem() == true) { if (isStripWicketTags() == true) { log.info("Strip Wicket tags also in development mode at default (see context.xml)."); Application.get().getMarkupSettings().setStripWicketTags(true); } getDebugSettings().setOutputMarkupContainerClassName(true); } log.info("Default TimeZone is: " + TimeZone.getDefault()); if ("UTC".equals(TimeZone.getDefault().getID()) == false) { for (final String str : UTC_RECOMMENDED) { log.fatal(str); } for (final String str : UTC_RECOMMENDED) { System.err.println(str); } } log.info("user.timezone is: " + System.getProperty("user.timezone")); cronSetup.initialize(); log.info(AppVersion.APP_ID + " " + AppVersion.NUMBER + " (" + AppVersion.RELEASE_TIMESTAMP + ") initialized."); PFUserContext.setUser(DatabaseUpdateDao.__internalGetSystemAdminPseudoUser()); // Logon admin user. if (systemUpdater.isUpdated() == false) { // Force redirection to update page: UserFilter.setUpdateRequiredFirst(true); } PFUserContext.setUser(null); UserXmlPreferencesCache.setInternalInstance(userXmlPreferencesCache); LoginHandler loginHandler; if (StringUtils.isNotBlank(configXml.getLoginHandlerClass()) == true) { loginHandler = (LoginHandler) BeanHelper.newInstance(configXml.getLoginHandlerClass()); } else { loginHandler = new LoginDefaultHandler(); } if (loginHandler == null) { log.error("Can't load login handler '" + configXml.getLoginHandlerClass() + "'. No login will be possible!"); } else { loginHandler.initialize(); Login.getInstance().setLoginHandler(loginHandler); } try { StorageClient.getInstance(); // Initialize storage } catch (final Exception ex) { log.error(ex.getMessage(), ex); } getPageSettings().setRecreateMountedPagesAfterExpiry(false); // initialize ical4j to be more "relaxed" CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true); CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_UNFOLDING, true); CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION, true); // initialize styles compiler try { final LessWicketApplicationInstantiator lessInstantiator = new LessWicketApplicationInstantiator(this, "styles", "projectforge.less", "projectforge.css"); lessInstantiator.instantiate(); } catch (final Exception e) { log.error("Unable to instantiate wicket less compiler", e); } }
From source file:org.springframework.beans.factory.wiring.BeanConfigurerSupport.java
/** * Configure the bean instance.// w ww . j a v a 2 s . c o m * <p>Subclasses can override this to provide custom configuration logic. * Typically called by an aspect, for all bean instances matched by a pointcut. * @param beanInstance the bean instance to configure (must <b>not</b> be {@code null}) */ public void configureBean(Object beanInstance) { if (this.beanFactory == null) { if (logger.isDebugEnabled()) { logger.debug("BeanFactory has not been set on " + ClassUtils.getShortName(getClass()) + ": " + "Make sure this configurer runs in a Spring container. Unable to configure bean of type [" + ClassUtils.getDescriptiveType(beanInstance) + "]. Proceeding without injection."); } return; } BeanWiringInfoResolver bwiResolver = this.beanWiringInfoResolver; Assert.state(bwiResolver != null, "No BeanWiringInfoResolver available"); BeanWiringInfo bwi = bwiResolver.resolveWiringInfo(beanInstance); if (bwi == null) { // Skip the bean if no wiring info given. return; } ConfigurableListableBeanFactory beanFactory = this.beanFactory; Assert.state(beanFactory != null, "No BeanFactory available"); try { if (bwi.indicatesAutowiring() || (bwi.isDefaultBeanName() && bwi.getBeanName() != null && !beanFactory.containsBean(bwi.getBeanName()))) { // Perform autowiring (also applying standard factory / post-processor callbacks). beanFactory.autowireBeanProperties(beanInstance, bwi.getAutowireMode(), bwi.getDependencyCheck()); beanFactory.initializeBean(beanInstance, bwi.getBeanName()); } else { // Perform explicit wiring based on the specified bean definition. beanFactory.configureBean(beanInstance, bwi.getBeanName()); } } catch (BeanCreationException ex) { Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause; String bceBeanName = bce.getBeanName(); if (bceBeanName != null && beanFactory.isCurrentlyInCreation(bceBeanName)) { if (logger.isDebugEnabled()) { logger.debug("Failed to create target bean '" + bce.getBeanName() + "' while configuring object of type [" + beanInstance.getClass().getName() + "] - probably due to a circular reference. This is a common startup situation " + "and usually not fatal. Proceeding without injection. Original exception: " + ex); } return; } } throw ex; } }