List of usage examples for org.springframework.context ConfigurableApplicationContext getBeanFactory
ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;
From source file:com.apress.prospringintegration.corespring.iocbasics.BasicIoCMain.java
public static void main(String[] args) { ApplicationContext app = new ClassPathXmlApplicationContext("ioc_basics.xml"); BasicPOJO basicPOJO = (BasicPOJO) app.getBean("basic-pojo"); assert basicPOJO != null; System.out.println(basicPOJO.getColor()); ColorEnum colorEnum = (ColorEnum) app.getBean("randomColor"); System.out.println("randomColor: " + colorEnum); colorEnum = (ColorEnum) app.getBean("exclusiveColor"); System.out.println("exclusiveColor: " + colorEnum); ColorPicker colorPicker = (ColorPicker) app.getBean(ColorPicker.class); assert colorPicker != null; System.out.println(colorPicker.getColorRandomizer().randomColor()); BasicIoCMain.demonstrateScopes(app); // Custom Scope Registration with SimpleThreadScope ConfigurableApplicationContext configApp = (ConfigurableApplicationContext) app; configApp.getBeanFactory().registerScope("thread", new SimpleThreadScope()); }
From source file:mk.finki.ranggo.aggregator.Aggregator.java
public static void main(String[] args) { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "classpath:spring/application-config.xml"); //make sure alchemyapi.key hold your license key final String alchemyapi_key = context.getBeanFactory().resolveEmbeddedValue("${alchemyapi.key}"); PersonRepository personRepository = context.getBean(PersonRepository.class); ContentRepository contentRepository = context.getBean(ContentRepository.class); ContentsAggregator aggregator = new ContentsAggregatorImpl(alchemyapi_key, personRepository, contentRepository);//from www . j a v a 2 s . co m //populates the data store with the test dataset Aggregator.test(aggregator); //executes update method Aggregator.update(null, aggregator); context.close(); }
From source file:org.fcrepo.upgrade.utils.TechnicalMetadataMigrator.java
/** * Migrate technical metadata./*from w ww. j av a 2 s . co m*/ * @param args If "dryrun" is passed as an argument, the utility will print out what would be done, * but no changes will be made. **/ public static void main(final String[] args) { ConfigurableApplicationContext ctx = null; try { final boolean dryrun; if (args.length > 0 && "dryrun".equals(args[0])) { dryrun = true; } else { dryrun = false; } final TechnicalMetadataMigrator migrator = new TechnicalMetadataMigrator(); ctx = new ClassPathXmlApplicationContext("classpath:/spring/master.xml"); ctx.getBeanFactory().autowireBeanProperties(migrator, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); migrator.run(dryrun); } catch (RepositoryException ex) { ex.printStackTrace(); } finally { if (null != ctx) { ctx.close(); } } }
From source file:com.example.config.ApplicationBuilder.java
public static void start(ConfigurableApplicationContext context) { if (!hasListeners(context)) { ((DefaultListableBeanFactory) context.getBeanFactory()).registerDisposableBean(SHUTDOWN_LISTENER, new ShutdownApplicationListener()); new BeanCountingApplicationListener().log(context); logger.info(STARTUP);//from w w w. j av a 2 s. co m } HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build(); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); HttpServer httpServer = HttpServer.create().host("localhost") .port(context.getEnvironment().getProperty("server.port", Integer.class, 8080)).handle(adapter); httpServer.bindUntilJavaShutdown(Duration.ofSeconds(60), disposable -> disposable.dispose()); }
From source file:org.echocat.jomon.spring.ApplicationContextUtils.java
@Nullable public static Class<?> findTypeOfBeanDefinition(@Nonnull ConfigurableApplicationContext applicationContext, @Nonnull String beanName) { return BeanFactoryUtils.findTypeOfBeanDefinition(applicationContext.getBeanFactory(), beanName); }
From source file:org.echocat.jomon.spring.ApplicationContextUtils.java
@Nullable public static String findScopeOfBeanDefinition(@Nonnull ConfigurableApplicationContext applicationContext, @Nonnull String beanName) { return BeanFactoryUtils.findScopeOfBeanDefinition(applicationContext.getBeanFactory(), beanName); }
From source file:me.springframework.di.spring.SinkTypeTest.java
private static Configuration readConfiguration(Resource resource) { JavaDocBuilder builder = new JavaDocBuilder(); builder.addSourceTree(Paths.getFile("src/test/java")); Augmentation[] augmentations = { new QDoxAugmentation(builder), new AutowiringAugmentation(builder), }; SpringConfigurationLoader loader = new SpringConfigurationLoader(augmentations); ConfigurableApplicationContext ctxt = new ClassPathXmlApplicationContext(resource.getFilename()); Configuration configuration = loader.load(ctxt.getBeanFactory()); return configuration; }
From source file:me.springframework.di.spring.AliasTest.java
private static Configuration readConfiguration(Resource resource) { JavaDocBuilder builder = new JavaDocBuilder(); builder.addSourceTree(Paths.getFile("src/test/java")); Augmentation[] augmentations = { new QDoxAugmentation(builder), new AutowiringAugmentation(builder) }; SpringConfigurationLoader loader = new SpringConfigurationLoader(augmentations); ConfigurableApplicationContext ctxt = new ClassPathXmlApplicationContext(resource.getFilename()); Configuration configuration = loader.load(ctxt.getBeanFactory()); return configuration; }
From source file:org.solmix.runtime.support.spring.ContainerPostProcessor.java
private static Container getContainerByName(String name, ApplicationContext context, boolean create) { if (!context.containsBean(name) && (create || Container.DEFAULT_CONTAINER_ID.equals(name))) { SpringContainer b = new SpringContainer(); ConfigurableApplicationContext cctx = (ConfigurableApplicationContext) context; cctx.getBeanFactory().registerSingleton(name, b); b.setApplicationContext(context); }//from w ww . j a va2 s . c o m return context.getBean(name, Container.class); }
From source file:org.solmix.runtime.support.spring.ContainerPostProcessor.java
/**Container,container?*/ public static Container addDefault(ApplicationContext ctx) { if (!ctx.containsBean(Container.DEFAULT_CONTAINER_ID)) { Container b = getContainerByName(Container.DEFAULT_CONTAINER_ID, ctx, true); if (ctx instanceof ConfigurableApplicationContext) { ConfigurableApplicationContext cctx = (ConfigurableApplicationContext) ctx; new ContainerPostProcessor(b).postProcessBeanFactory(cctx.getBeanFactory()); }/* w w w. j a va2 s. com*/ } return Container.class.cast(ctx.getBean(Container.DEFAULT_CONTAINER_ID, Container.class)); }