本文整理匯總了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext.getBean方法的典型用法代碼示例。如果您正苦於以下問題:Java AnnotationConfigApplicationContext.getBean方法的具體用法?Java AnnotationConfigApplicationContext.getBean怎麽用?Java AnnotationConfigApplicationContext.getBean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.context.annotation.AnnotationConfigApplicationContext
的用法示例。
在下文中一共展示了AnnotationConfigApplicationContext.getBean方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: provideCollectorComponent_canSetConsumerGroupName
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
@Test
public void provideCollectorComponent_canSetConsumerGroupName() {
String consumerGroupName = "pashmak";
context = new AnnotationConfigApplicationContext();
addEnvironment(context, "zipkin.collector.eventhub.storageConnectionString:" + dummyEventHubConnectionString);
addEnvironment(context, "zipkin.collector.eventhub.eventHubConnectionString:" + dummyStorageConnectionString );
addEnvironment(context, "zipkin.collector.eventhub.consumerGroupName:" + consumerGroupName);
context.register(PropertyPlaceholderAutoConfiguration.class,
EventHubCollectorAutoConfiguration.class,
InMemoryConfiguration.class);
context.refresh();
EventHubCollector collector = context.getBean(EventHubCollector.class);
assertNotNull(collector);
assertEquals(consumerGroupName, collector.getConsumerGroupName());
}
開發者ID:aliostad,項目名稱:zipkin-collector-eventhub,代碼行數:19,代碼來源:EventHubCollectorAutoConfigurationTest.java
示例2: setUp
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
@Before
public void setUp() throws IOException {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(TarantoolConfiguration.class);
DockerPort dockerPort = docker.containers()
.container("tarantool")
.port(3301);
ImmutableMap<String, Object> env = ImmutableMap.of("tarantoolPort", dockerPort.getExternalPort());
applicationContext.getEnvironment().getPropertySources()
.addFirst(new MapPropertySource("rule", env));
applicationContext.refresh();
TarantoolClientOps bean = (TarantoolClientOps) applicationContext.getBean("tarantoolSyncOps");
String eval = IOUtils.toString(RepositoryIntegrationTests.class.getResource("/init.lua"));
bean.eval(eval);
//
userRepository = applicationContext.getBean(UserRepository.class);
userRepository.deleteAll();
logEntryRepository = applicationContext.getBean(LogEntryRepository.class);
logEntryRepository.deleteAll();
addressRepository = applicationContext.getBean(AddressRepository.class);
addressRepository.deleteAll();
}
示例3: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ApplicationConfig.class);
ctx.refresh();
System.out.println("Spring Framework Version: " + SpringVersion.getVersion());
System.out.println("Spring Boot Version: " + SpringBootVersion.getVersion());
JpaUI ui = ctx.getBean(JpaUI.class);
ui.init();
ctx.close();
}
示例4: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
PrePostConfig.class);
BeanWayService beanWayService = context.getBean(BeanWayService.class);
JSR250WayService jsr250WayService = context.getBean(JSR250WayService.class);
context.close();
}
示例5: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
/**
* @param args
*/
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
PrePostConfig.class);
context.getBean(BeanWayService.class);
context.getBean(Jsr250WayService.class);
context.close();
}
示例6: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(BeanConfig.class);
System.out.println("application context loaded.");
context.refresh();
System.out.println("*********The empRec1 bean ***************");
Employee empRec1 = (Employee) context.getBean("empRec1");
System.out.println("*********The empRec2 bean ***************");
Employee empRec2 = (Employee) context.getBean("empRec2");
Department dept2 = empRec2.getDept();
System.out.println("First Name: " + empRec2.getFirstName());
System.out.println("Last Name: " + empRec2.getLastName());
System.out.println("Birthdate: " + empRec2.getBirthdate());
System.out.println("Salary: " + empRec2.getSalary());
System.out.println("Dept. Name: " + dept2.getDeptName());
System.out.println("*********The empRec3 bean ***************");
Employee empRec3 = (Employee) context.getBean("empRec3");
Department dept3 = empRec3.getDept();
System.out.println("First Name: " + empRec3.getFirstName());
System.out.println("Last Name: " + empRec3.getLastName());
System.out.println("Birthdate: " + empRec3.getBirthdate());
System.out.println("Salary: " + empRec3.getSalary());
System.out.println("Dept. Name: " + dept3.getDeptName());
System.out.println("*********The empRec4 bean ***************");
Employee empRec4 = (Employee) context.getBean("empRec4");
Department dept4 = empRec4.getDept();
System.out.println("First Name: " + empRec4.getFirstName());
System.out.println("Last Name: " + empRec4.getLastName());
System.out.println("Birthdate: " + empRec4.getBirthdate());
System.out.println("Salary: " + empRec4.getSalary());
System.out.println("Dept. Name: " + dept4.getDeptName());
context.registerShutdownHook();
}
示例7: testSpringAutoStartupFalse
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
@Test
public void testSpringAutoStartupFalse() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TestConfigAutoStartupFalse.class);
ctx.start();
try {
Engine engine = ctx.getBean(Engine.class);
assertFalse(engine.isRunning());
assertFalse(engine.isError());
} finally {
ctx.close();
}
}
示例8: vocabularyLocationCanBeCustomized
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
@Test
public void vocabularyLocationCanBeCustomized() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "inception.vocabularyLocation:/remote");
context.register(Conf.class);
context.refresh();
TwitterSentimentProcessorProperties properties = context.getBean(TwitterSentimentProcessorProperties.class);
assertThat(properties.getVocabularyLocation(), equalTo(context.getResource("/remote")));
}
開發者ID:tzolov,項目名稱:tensorflow-spring-cloud-stream-app-starters,代碼行數:10,代碼來源:TwitterSentimentProcessorPropertiesTest.java
示例9: setUp
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
@Before
public void setUp() {
context = new AnnotationConfigApplicationContext(SearchConfiguration.class);
context.start();
repository = context.getBean(GaeSearchRepository.class);
repository.save(new SearchData(1L, 10, "Baz"));
}
示例10: should_collect_all_bean_definitions
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
@Test
public void should_collect_all_bean_definitions() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ValidContext.class);
SpringQueueCollector collector = context.getBean(SpringQueueCollector.class);
assertThat(collector.getProducers().size(), equalTo(2));
assertThat(collector.getConsumers().size(), equalTo(2));
assertThat(collector.getTransformers().size(), equalTo(2));
assertThat(collector.getShardRouters().size(), equalTo(2));
assertThat(collector.getTaskListeners().size(), equalTo(2));
assertThat(collector.getThreadListeners().size(), equalTo(2));
assertThat(collector.getExecutors().size(), equalTo(2));
}
示例11: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TaskExecutorConfig.class);
AsyncTaskService asyncTaskService = context.getBean(AsyncTaskService.class);
int nums = 10;
for (int i = 0; i < nums; i++) {
asyncTaskService.executeAsyncTask(i);
asyncTaskService.executeAsyncTaskPlus(i);
}
context.close();
}
示例12: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ScopeConfig.class);
DemoSingletonService s1 = context.getBean(DemoSingletonService.class);
DemoSingletonService s2 = context.getBean(DemoSingletonService.class);
DemoPrototypeService p1 = context.getBean(DemoPrototypeService.class);
DemoPrototypeService p2 = context.getBean(DemoPrototypeService.class);
System.out.println("s1與s2是否相等:" + s1.equals(s2));
System.out.println("p1與p2是否相等:" + p1.equals(p2));
context.close();
}
示例13: check
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
private void check(int expectedTimeout, int expectedBatch, Class<?>... annotatedClasses) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(annotatedClasses);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(expectedTimeout, bean.getTimeout());
assertEquals(expectedBatch, bean.getBatch());
}
示例14: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext();
context.register(AppConfiguration.class);
context.refresh();
ReportGenerator generator = (ReportGenerator) context.getBean("generator1");
generator.format();
}
示例15: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DemoConfig.class);
AnnoDemoService demoService = context.getBean(AnnoDemoService.class);
demoService.outputResult();
context.close();
}