List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext refresh
@Override public void refresh() throws BeansException, IllegalStateException
From source file:com.comcast.cats.domain.configuration.CatsHomeTest.java
public CatsHomeTest() { setCatsHome(getTargetDirectory());/*www. java2 s . c o m*/ AnnotationConfigApplicationContext appCtx = new AnnotationConfigApplicationContext(); appCtx.register(CatsHome.class); appCtx.refresh(); ctx = appCtx; }
From source file:org.seasar.doma.boot.autoconfigure.TryLookupEntityListenerProviderTest.java
@Test public void testManaged() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(FooListener.class); context.refresh(); TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider(); provider.setApplicationContext(context); FooListener listener = provider.get(FooListener.class, FooListener::new); assertThat(listener.managed, is(true)); }
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 w ww . j a v a 2s. c om 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:org.jboss.arquillian.spring.integration.javaconfig.utils.AnnotationApplicationContextProducer.java
/** * <p>Creates instance of {@link AnnotationConfigApplicationContext} class.</p> * * @param classes the annotated classes to register * @param packages the packages containing the annotated classes * * @return the created instance of {@link AnnotationConfigApplicationContext} *//*from w ww . j a va 2 s.co m*/ private ApplicationContext createAnnotatedApplicationContext(Class<?>[] classes, String[] packages) { if (classes.length > 0) { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(classes); if (packages.length > 0) { applicationContext.scan(packages); applicationContext.refresh(); } return applicationContext; } else { return new AnnotationConfigApplicationContext(packages); } }
From source file:example.tests.InitialLoadTest.java
private ApplicationContext createSingleInstanceAppContext(MongoClient mongo) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.getBeanFactory().registerSingleton("mongoClient", new SimpleMongoDbFactory(mongo, "exampleDb")); context.refresh(); return context; }
From source file:com.bank.config.code.IntegrationTests.java
@Test public void transferTenDollars() throws InsufficientFundsException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.getEnvironment().setDefaultProfiles("dev"); ctx.register(TransferServiceConfig.class, StandaloneDataConfig.class, JndiDataConfig.class); ctx.refresh(); TransferService transferService = ctx.getBean(TransferService.class); AccountRepository accountRepository = ctx.getBean(AccountRepository.class); assertThat(accountRepository.findById("A123").getBalance(), equalTo(100.00)); assertThat(accountRepository.findById("C456").getBalance(), equalTo(0.00)); transferService.transfer(10.00, "A123", "C456"); assertThat(accountRepository.findById("A123").getBalance(), equalTo(90.00)); assertThat(accountRepository.findById("C456").getBalance(), equalTo(10.00)); }
From source file:org.wicket_sapporo.springApp.SpringApplication.java
/** * Spring?Injector??.//from w w w .ja v a 2s .co m */ protected void initSpring() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); // ???Bean??? ctx.scan("org.wicket_sapporo.springApp.service"); ctx.refresh(); getComponentInstantiationListeners().add(new SpringComponentInjector(this, ctx)); }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void ttlCanBeCustomized() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "ttl:" + 1000); context.register(Conf.class); context.refresh(); CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getTtl(), equalTo(1000)); context.close();// w w w . jav a 2 s .c o m }
From source file:com.avanza.ymer.MirrorEnvironment.java
public ApplicationContext getMongoClientContext() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.getBeanFactory().registerSingleton("mongoDbFactory", new SimpleMongoDbFactory(mongoServer.getMongo(), TEST_MIRROR_DB_NAME)); context.refresh(); return context; }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void ingestQueryCanBeCustomized() { String query = "insert into book (isbn, title, author) values (?, ?, ?)"; AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "ingest-query:" + query); context.register(Conf.class); context.refresh(); CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getIngestQuery(), equalTo(query)); context.close();/* www . jav a 2s .c om*/ }