use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.
the class SampleBitronixApplication method main.
public static void main(String[] args) throws Exception {
ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class, args);
AccountService service = context.getBean(AccountService.class);
AccountRepository repository = context.getBean(AccountRepository.class);
service.createAccountAndNotify("josh");
System.out.println("Count is " + repository.count());
try {
service.createAccountAndNotify("error");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
System.out.println("Count is " + repository.count());
Thread.sleep(100);
((Closeable) context).close();
}
use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.
the class SampleNarayanaApplication method main.
public static void main(String[] args) throws Exception {
ApplicationContext context = SpringApplication.run(SampleNarayanaApplication.class, args);
AccountService service = context.getBean(AccountService.class);
AccountRepository repository = context.getBean(AccountRepository.class);
service.createAccountAndNotify("josh");
System.out.println("Count is " + repository.count());
try {
// Using username "error" will cause service to throw SampleRuntimeException
service.createAccountAndNotify("error");
} catch (SampleRuntimeException ex) {
// Log message to let test case know that exception was thrown
System.out.println(ex.getMessage());
}
System.out.println("Count is " + repository.count());
((Closeable) context).close();
}
use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.
the class MockitoTestExecutionListener method injectFields.
private void injectFields(TestContext testContext, DefinitionsParser parser) {
ApplicationContext applicationContext = testContext.getApplicationContext();
MockitoPostProcessor postProcessor = applicationContext.getBean(MockitoPostProcessor.class);
for (Definition definition : parser.getDefinitions()) {
Field field = parser.getField(definition);
if (field != null) {
postProcessor.inject(field, testContext.getTestInstance(), definition);
}
}
}
use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.
the class SpyBeanOnContextHierarchyIntegrationTests method testSpying.
@Test
public void testSpying() throws Exception {
ApplicationContext context = this.childConfig.getContext();
ApplicationContext parentContext = context.getParent();
assertThat(parentContext.getBeanNamesForType(ExampleService.class)).hasSize(1);
assertThat(parentContext.getBeanNamesForType(ExampleServiceCaller.class)).hasSize(0);
assertThat(context.getBeanNamesForType(ExampleService.class)).hasSize(0);
assertThat(context.getBeanNamesForType(ExampleServiceCaller.class)).hasSize(1);
assertThat(context.getBean(ExampleService.class)).isNotNull();
assertThat(context.getBean(ExampleServiceCaller.class)).isNotNull();
}
use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.
the class ApplicationContextTestUtilsTests method closeNonClosableContext.
@Test
public void closeNonClosableContext() {
ApplicationContext mock = mock(ApplicationContext.class);
ApplicationContextTestUtils.closeAll(mock);
}
Aggregations