List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getAutowireCapableBeanFactory
@Override public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException
From source file:com.searchbox.collection.oppfin.IdealISTCollection.java
public static void main(String... args) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException, SAXException, IOException { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( RootConfiguration.class); IdealISTCollection collection = context.getAutowireCapableBeanFactory() .createBean(IdealISTCollection.class); collection.synchronize();//from w w w. j av a2 s . c o m }
From source file:com.kurento.kmf.spring.KurentoApplicationContextUtils.java
public static void processInjectionBasedOnApplicationContext(Object bean, AnnotationConfigApplicationContext appContext) { Assert.notNull(appContext,//from w w w. j ava 2 s .c o m "Cannot process bean injection. Reason the specified ApplicationContext is null"); Assert.notNull(bean, "Cannot process bean injection into null bean reference"); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(appContext.getAutowireCapableBeanFactory()); bpp.processInjection(bean); }
From source file:fr.javatronic.damapping.test.injectable.SpringHotelControllerTest.java
@BeforeClass public void setup() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( SpringHotelControllerConfiguration.class); this.hotelController = ctx.getAutowireCapableBeanFactory().getBean(HotelController.class); ctx.start();/* w ww . jav a 2s. c om*/ }
From source file:otherpackage.MyConfigurerTests.java
@SuppressWarnings("resource") private void loadContext(Class<?> clazz) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(clazz); context.getAutowireCapableBeanFactory().autowireBean(this); }
From source file:io.logspace.it.InfrastructureRule.java
private void injectDependencies() throws IllegalAccessException { Field field = getField(this.logspaceHq.getClass(), "context"); field.setAccessible(true);//from w w w . j a v a 2 s . c o m AnnotationConfigApplicationContext applicationContext = (AnnotationConfigApplicationContext) field .get(this.logspaceHq); applicationContext.getAutowireCapableBeanFactory().autowireBean(this); }
From source file:org.zephyrsoft.sdb2.Start.java
private Start(String[] args) { LOG.debug("starting application"); // parse command line arguments CmdLineParser parser = new CmdLineParser(options); parser.setUsageWidth(80);//from www . ja va 2 s .co m try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); options.setHelp(true); } if (options.isHelp()) { System.err.println("The available options are:"); parser.printUsage(System.err); } else { try { // set encoding to UTF-8 (the cache has to be reset to make the new definition effective) System.setProperty("file.encoding", "UTF-8"); Field charset = Charset.class.getDeclaredField("defaultCharset"); charset.setAccessible(true); charset.set(null, null); LOG.info("default time zone is {}", ZoneId.systemDefault().getId()); LOG.info("loading application context"); @SuppressWarnings("resource") AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(SpringConfiguration.class); context.refresh(); context.getAutowireCapableBeanFactory().autowireBean(this); mainController.loadSongs(options.getSongsFile()); mainWindow.startup(); } catch (Exception e) { LOG.error("problem while starting up the application", e); System.exit(-1); } } }
From source file:com.doctor.spring4.blog.code.WireObjectDependenciesOutsideSpring.java
/** * Instantiate the bean and then inject dependencies using AutoWireCapableBeanFactory.autowireBean(instance) * beanperson??/*from www . j a v a 2 s . c om*/ */ @Test public void test_create_bean_and_inject_dependencies() { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( SpringConfig.class); Person person = (Person) applicationContext.getAutowireCapableBeanFactory().createBean(Person.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); assertNotNull(person.getContext()); Stream.of(applicationContext.getBeanDefinitionNames()).forEach(System.out::println); applicationContext.close(); }
From source file:shiver.me.timbers.spring.security.JwtSpringSecurityAdaptor.java
private void autowireThis(HttpSecurity http) { final ApplicationContext parent = http.getSharedObject(ApplicationContext.class); checkForJwtAnnotation(parent);//from ww w. j a v a 2 s . c o m final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.setParent(parent); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(getClass()); context.refresh(); context.getAutowireCapableBeanFactory().autowireBean(this); }
From source file:com.doctor.spring4.blog.code.WireObjectDependenciesOutsideSpring.java
/** * Instantiate the bean and then inject dependencies using AutoWireCapableBeanFactory.autowireBean(instance) *///from ww w . j av a2s .co m @Test public void test_only_inject_dependencies() { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( SpringConfig.class); Person person = new Person(); assertNull(person.getContext()); applicationContext.getAutowireCapableBeanFactory().autowireBean(person); assertNotNull(person.getContext()); Stream.of(applicationContext.getBeanDefinitionNames()).forEach(System.out::println); applicationContext.close(); }
From source file:com.doctor.spring4.blog.code.WireObjectDependenciesOutsideSpring.java
/** * ??spring??//from w w w .j av a 2 s . com * * @see http://www.javacodegeeks.com/2012/03/integrating-spring-into-legacy.html * */ @Test public void test_registerSingleton() { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( SpringConfig.class); Person person = new Person(); assertNull(person.getContext()); applicationContext.getBeanFactory().registerSingleton("person", person); assertNotNull(applicationContext.getBean(Person.class)); assertNull(person.getContext()); applicationContext.getAutowireCapableBeanFactory().autowireBean(person); assertNotNull(person.getContext()); Stream.of(applicationContext.getBeanDefinitionNames()).forEach(System.out::println); applicationContext.close(); }