本文整理汇总了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationConfigApplicationContext类的具体用法?Java AnnotationConfigApplicationContext怎么用?Java AnnotationConfigApplicationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationConfigApplicationContext类属于org.springframework.context.annotation包,在下文中一共展示了AnnotationConfigApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideCollectorComponent_canSetStorageContainerName
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
@Test
public void provideCollectorComponent_canSetStorageContainerName() {
String storageContainerName = "pashmak";
context = new AnnotationConfigApplicationContext();
addEnvironment(context, "zipkin.collector.eventhub.storageConnectionString:" + dummyEventHubConnectionString);
addEnvironment(context, "zipkin.collector.eventhub.eventHubConnectionString:" + dummyStorageConnectionString );
addEnvironment(context, "zipkin.collector.eventhub.storageContainerName:" + storageContainerName);
context.register(PropertyPlaceholderAutoConfiguration.class,
EventHubCollectorAutoConfiguration.class,
InMemoryConfiguration.class);
context.refresh();
EventHubCollector collector = context.getBean(EventHubCollector.class);
assertNotNull(collector);
assertEquals(storageContainerName, collector.getStorageContainerName());
}
开发者ID:aliostad,项目名称:zipkin-collector-eventhub,代码行数:19,代码来源:EventHubCollectorAutoConfigurationTest.java
示例2: testCamelProducer
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
@Test
public void testCamelProducer() throws Exception {
// Starting Spring context.
try (GenericApplicationContext context = new AnnotationConfigApplicationContext(ExampleConfiguration.class)) {
context.start();
// Sending Camel message.
CamelContext camel = context.getBean(CamelContext.class);
ProducerTemplate producerTemplate = camel.createProducerTemplate();
producerTemplate.sendBody("direct:start", "Send me to the Sponge");
// Waiting for the engine to process an event.
Engine engine = context.getBean(Engine.class);
await().atMost(60, TimeUnit.SECONDS)
.until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get());
assertFalse(engine.isError());
context.stop();
}
}
示例3: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
public static void main (String [] args)
{
@SuppressWarnings({ "resource"})
AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
PumpEngine engine = (PumpEngine)context.getBean(PumpEngine.class);
engine.setArgs(args);
try {
engine.startPump();
} catch (Exception e) {
logger.error("Exception Occured while doing buy/sell transaction", e);
}
System.out.println("\n\n\nHope you will make a profit in this pump ;)");
System.out.println("if you could make a proit using this app please conside doing some donation with 1$ or 2$ to BTC address 1PfnwEdmU3Ki9htakiv4tciPXzo49RRkai \nit will help us doing more features in the future");
}
示例4: init
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
public void init() {
//启动并设置Spring
AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
ctx.registerShutdownHook();
NContext.setApplicationContext(ctx);
//初始化房间管理器
HomeManager homeManager = HomeManager.getInstance();
homeManager.init();
//初始化用户管理器
PlayerManager playerManager = PlayerManager.getInstance();
playerManager.init();
//初始化Gateway
ClientManager clientManager = ClientManager.getInstance();
clientManager.init();
//启动异步处理器
AsyncProcessor asyncProcessor = AsyncProcessor.getInstance();
asyncProcessor.start();
//启动滴答服务
TickerService tickerService = TickerService.getInstance();
tickerService.start();
}
示例5: createAndFailWithCause
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
private void createAndFailWithCause(String cause) {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(MediaServicesAutoConfiguration.class);
Exception exception = null;
try {
context.refresh();
} catch (Exception e) {
exception = e;
}
assertThat(exception).isNotNull();
assertThat(exception).isExactlyInstanceOf(BeanCreationException.class);
assertThat(exception.getCause().getCause().toString()).contains(cause);
}
}
示例6: test
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
@Test
public void test() {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(this.getClass().getPackage().getName());
Bean bean = context.getBean(Bean.class);
Assert.assertEquals("aValue", bean.resolver.resolveStringValue("${a}"));
try {
bean.resolver.resolveStringValue("${b}");
Assert.fail("must throw exception");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Could not resolve placeholder 'b' in string value \"${b}\"", e.getMessage());
}
context.close();
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:TestLastPropertyPlaceholderConfigurer.java
示例7: 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 empRec1A = (Employee) context.getBean("empRec1");
System.out.println("instance A: " + empRec1A.hashCode());
Employee empRec1B = (Employee) context.getBean("empRec1");
System.out.println("instance B: " +empRec1B.hashCode());
System.out.println("*********The empRec2 bean ***************");
Employee empRec2A = (Employee) context.getBean("empRec2");
System.out.println("instance A: " + empRec2A.hashCode());
Employee empRec2B = (Employee) context.getBean("empRec2");
System.out.println("instance B: " + empRec2B.hashCode());
context.registerShutdownHook();
}
示例8: provideCollectorComponent_canSetCheckpointBatchSize
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
@Test
public void provideCollectorComponent_canSetCheckpointBatchSize() {
int checkpointBatchSize = 1000;
context = new AnnotationConfigApplicationContext();
addEnvironment(context, "zipkin.collector.eventhub.storageConnectionString:" + dummyEventHubConnectionString);
addEnvironment(context, "zipkin.collector.eventhub.eventHubConnectionString:" + dummyStorageConnectionString );
addEnvironment(context, "zipkin.collector.eventhub.checkpoint-batch-size:" + checkpointBatchSize);
context.register(PropertyPlaceholderAutoConfiguration.class,
EventHubCollectorAutoConfiguration.class,
InMemoryConfiguration.class);
context.refresh();
EventHubCollector collector = context.getBean(EventHubCollector.class);
assertNotNull(collector);
assertEquals(checkpointBatchSize, collector.getCheckpointBatchSize());
}
开发者ID:aliostad,项目名称:zipkin-collector-eventhub,代码行数:19,代码来源:EventHubCollectorAutoConfigurationTest.java
示例9: enableSpringWebSessionConfiguresThings
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
@Test
public void enableSpringWebSessionConfiguresThings() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(GoodConfig.class);
this.context.refresh();
WebSessionManager webSessionManagerFoundByType = this.context.getBean(WebSessionManager.class);
Object webSessionManagerFoundByName = this.context.getBean(WebHttpHandlerBuilder.WEB_SESSION_MANAGER_BEAN_NAME);
assertThat(webSessionManagerFoundByType).isNotNull();
assertThat(webSessionManagerFoundByName).isNotNull();
assertThat(webSessionManagerFoundByType).isEqualTo(webSessionManagerFoundByName);
assertThat(this.context.getBean(ReactiveSessionRepository.class)).isNotNull();
}
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:17,代码来源:ReactiveMongoWebSessionConfigurationTest.java
示例10: main
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
IToDoListDAO repository = context.getBean(IToDoListDAO.class);
// fetch all ToDoLists
System.out.println("ToDoLists found with findAll():");
System.out.println("-------------------------------");
for (ToDoList ToDoList : repository.findAll()) {
System.out.println(ToDoList);
}
System.out.println();
context.close();
}
示例11: createStorageAccountWithInvalidConnectionString
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
@Test
public void createStorageAccountWithInvalidConnectionString() {
System.setProperty(CONNECTION_STRING_PROPERTY, INVALID_CONNECTION_STRING);
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(StorageAutoConfiguration.class);
context.refresh();
CloudStorageAccount cloudStorageAccount = null;
try {
cloudStorageAccount = context.getBean(CloudStorageAccount.class);
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(BeanCreationException.class);
}
assertThat(cloudStorageAccount).isNull();
}
System.clearProperty(CONNECTION_STRING_PROPERTY);
}
示例12: verifyBeanCreationException
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
private void verifyBeanCreationException(String message, Class<?> beanClass) {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
Exception exception = null;
try {
context.register(ServiceBusAutoConfiguration.class);
context.refresh();
context.getBean(beanClass);
} catch (Exception e) {
exception = e;
}
assertThat(exception).isNotNull();
assertThat(exception.getMessage()).contains(message);
assertThat(exception).isExactlyInstanceOf(BeanCreationException.class);
}
}
示例13: canSetAllProperties
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
@Test
public void canSetAllProperties() {
PropertySettingUtil.setProperties();
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(Config.class);
context.refresh();
final DocumentDBProperties properties = context.getBean(DocumentDBProperties.class);
assertThat(properties.getUri()).isEqualTo(PropertySettingUtil.URI);
assertThat(properties.getKey()).isEqualTo(PropertySettingUtil.KEY);
assertThat(properties.getConsistencyLevel()).isEqualTo(PropertySettingUtil.CONSISTENCY_LEVEL);
assertThat(properties.isAllowTelemetry()).isEqualTo(PropertySettingUtil.ALLOW_TELEMETRY_TRUE);
}
PropertySettingUtil.unsetProperties();
}
示例14: httpBuilder
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
public static HttpServer httpBuilder (String connectionUrl) {
try {
URL url = new URL(connectionUrl);
AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringAnnotationConfig.class);
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(RequestContextFilter.class);
resourceConfig.property("contextConfig", annotationConfigApplicationContext);
resourceConfig.register(RestSupport.class);
URI baseUri = URI.create(url.getProtocol() + "://" + url.getAuthority());
return GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
} catch (Exception e) {
Assert.fail("Could'n parse configfile." + e.getMessage());
}
return null;
}
示例15: should_fail_on_invalid_queue_definitions
import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入依赖的package包/类
@Test
public void should_fail_on_invalid_queue_definitions() throws Exception {
try {
new AnnotationConfigApplicationContext(InvalidContext.class);
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("unable to collect queue beans:" + System.lineSeparator() +
"duplicate bean: name=testProducer2, class=SpringQueueProducer, queueId=test_queue" + System.lineSeparator() +
"duplicate bean: name=testConsumer2, class=SpringQueueConsumer, queueId=test_queue" + System.lineSeparator() +
"duplicate bean: name=testTransformer2, class=SpringTaskPayloadTransformer, queueId=test_queue" + System.lineSeparator() +
"duplicate bean: name=testShardRouter2, class=SpringQueueShardRouter, queueId=test_queue" + System.lineSeparator() +
"duplicate bean: name=springTaskLifecycleListener2, class=SpringTaskLifecycleListener, queueId=test_queue" + System.lineSeparator() +
"duplicate bean: name=springThreadLifecycleListener2, class=SpringThreadLifecycleListener, queueId=test_queue" + System.lineSeparator() +
"duplicate bean: name=springQueueExternalExecutor2, class=SpringQueueExternalExecutor, queueId=test_queue"));
return;
}
Assert.fail("context should not be constructed");
}