List of usage examples for org.springframework.beans.factory.support DefaultListableBeanFactory createBean
@Override public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException
From source file:com.gwtplatform.dispatch.rpc.server.spring.utils.SpringUtils.java
@SuppressWarnings("unchecked") public static <B> B instantiate(ApplicationContext applicationContext, Class<B> clazz) throws BeansException { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(applicationContext); return (B) beanFactory.createBean(clazz, AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR, false); }
From source file:org.openvpms.component.business.service.scheduler.JobRunner.java
/** * Creates the job./*from w w w .j av a2s. c o m*/ * * @return a new job * @throws ClassNotFoundException if the job class cannot be found */ private Job createJob() throws ClassNotFoundException { Job result; IMObjectBean bean = new IMObjectBean(configuration, service); Class type = Class.forName(bean.getString("class")); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(context); factory.registerSingleton("jobConfiguration", configuration); Object job = factory.createBean(type, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true); if (job instanceof Runnable) { result = new DelegatingJob((Runnable) job); } else { result = (Job) job; } return result; }
From source file:org.openvpms.web.component.im.table.IMObjectTableModelFactory.java
/** * Helper to create a new table model.//from w w w. ja v a2 s . com * * @param handler the archetype handler * @param shortNames the archetype short names. May be {@code null} * @param query the query. May be {@code null} * @param parent the parent object * @param context the layout context * @return a new table model, or {@code null} if there is no valid constructor */ @SuppressWarnings("unchecked") private static <T extends IMObject> IMObjectTableModel<T> construct( ArchetypeHandler<IMObjectTableModel<T>> handler, final String[] shortNames, Query<T> query, final IMObject parent, LayoutContext context) { Class type = handler.getType(); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); // Spring doesn't automatically autowire the shortNames array when it is registered as a singleton, so need to // register the following to handle it explicitly factory.setAutowireCandidateResolver(new SimpleAutowireCandidateResolver() { @Override public Object getSuggestedValue(DependencyDescriptor descriptor) { if (String[].class.equals(descriptor.getDependencyType())) { return shortNames; } return super.getSuggestedValue(descriptor); } }); if (query != null) { factory.registerSingleton("query", query); } if (parent != null) { factory.registerSingleton("parent", parent); } if (context != null) { factory.registerSingleton("context", context); } try { IMObjectTableModel<T> result = (IMObjectTableModel<T>) factory.createBean(type, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false); handler.initialise(result); return result; } catch (Throwable exception) { log.error(exception, exception); } return null; }