本文整理了Java中io.micronaut.context.ApplicationContext.createBean()
方法的一些代码示例,展示了ApplicationContext.createBean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.createBean()
方法的具体详情如下:
包路径:io.micronaut.context.ApplicationContext
类名称:ApplicationContext
方法名:createBean
暂无
代码示例来源:origin: micronaut-projects/micronaut-core
this.serviceInstance = applicationContext.createBean(NettyEmbeddedServerInstance.class, id, this);
applicationContext.publishEvent(new ServiceStartedEvent(serviceInstance));
});
代码示例来源:origin: micronaut-projects/micronaut-core
@BeforeClass
public static void setupServer() {
System.setProperty(Environment.BOOTSTRAP_CONTEXT_PROPERTY, "true");
Map<String, Object> map = new HashMap<>();
map.put(MockSpringCloudConfigServer.ENABLED, true);
map.put("micronaut.server.port", -1);
map.put("spring.cloud.config.enabled", false);
map.put("micronaut.environments", "dev,test");
springCloudServer = ApplicationContext.run(EmbeddedServer.class, map);
server = ApplicationContext.run(EmbeddedServer.class, CollectionUtils.mapOf(
"micronaut.environments","test",
"micronaut.application.name", "spring-config-sample",
"micronaut.config-client.enabled", true,
"spring.cloud.config.enabled", true,
"spring.cloud.config.uri", springCloudServer.getURI()
));
client = server
.getApplicationContext()
.createBean(HttpClient.class, LoadBalancer.fixed(server.getURL()));
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testStreamingClient() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxStreamingHttpClient client = embeddedServer.getApplicationContext().createBean(RxStreamingHttpClient.class, embeddedServer.getURL());
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testPostInvalidFormData() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::postform[]
Map<String, String> data = new LinkedHashMap<>();
data.put("title", "The Stand");
data.put("pages", "notnumber");
data.put("url", "noturl");
Flowable<HttpResponse<Book>> call = client.exchange(
POST("/binding/book", data)
.contentType(MediaType.APPLICATION_FORM_URLENCODED),
Book.class
);
// end::postform[]
thrown.expect(HttpClientResponseException.class);
thrown.expectMessage(CoreMatchers.startsWith("Failed to convert argument [pages] for value [notnumber]"));
HttpResponse<Book> response = call.blockingFirst();
embeddedServer.stop();
client.stop();
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testSimpleRetrieve() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::simple[]
String uri = UriBuilder.of("/hello/{name}")
.expand(Collections.singletonMap("name", "John"))
.toString();
assertEquals("/hello/John", uri);
String result = client.toBlocking().retrieve(uri);
assertEquals(
"Hello John",
result
);
// end::simple[]
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testGetPojoList() {
ApplicationContext applicationContext = ApplicationContext.run();
EmbeddedServer server = applicationContext.getBean(EmbeddedServer.class).start();
HttpClient client = applicationContext.createBean(HttpClient.class, server.getURL());
Flowable<HttpResponse<List>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/get/pojoList"), Argument.of(List.class, HttpGetSpec.Book.class)
));
HttpResponse<List> response = flowable.blockingFirst();
assertEquals(response.getStatus(), HttpStatus.OK);
Optional<List> body = response.getBody();
assertTrue(body.isPresent());
List<HttpGetSpec.Book> list = body.get();
assertEquals(list.size(), 1);
assertTrue(list.get(0) instanceof HttpGetSpec.Book);
client.stop();
applicationContext.stop();
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testRetrieveWithJSON() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::jsonmap[]
Flowable<Map> response = client.retrieve(
GET("/greet/John"), Map.class
);
// end::jsonmap[]
assertEquals(
"Hello John",
response.blockingFirst().get("text")
);
// tag::jsonmaptypes[]
response = client.retrieve(
GET("/greet/John"),
Argument.of(Map.class, String.class, String.class) // <1>
);
// end::jsonmaptypes[]
assertEquals(
"Hello John",
response.blockingFirst().get("text")
);
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testRetrieveWithPOJOResponse() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::pojoresponse[]
Flowable<HttpResponse<Message>> call = client.exchange(
GET("/greet/John"), Message.class // <1>
);
HttpResponse<Message> response = call.blockingFirst();
Optional<Message> message = response.getBody(Message.class); // <2>
// check the status
assertEquals(
HttpStatus.OK,
response.getStatus() // <3>
);
// check the body
assertTrue(message.isPresent());
assertEquals(
"Hello John",
message.get().getText()
);
// end::pojoresponse[]
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testPostWithURITemplate() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::posturitemplate[]
Flowable<HttpResponse<Book>> call = client.exchange(
POST("/amazon/book/{title}", new Book("The Stand")),
Book.class
);
// end::posturitemplate[]
HttpResponse<Book> response = call.blockingFirst();
Optional<Book> message = response.getBody(Book.class); // <2>
// check the status
assertEquals(
HttpStatus.CREATED,
response.getStatus() // <3>
);
// check the body
assertTrue(message.isPresent());
assertEquals(
"The Stand",
message.get().getTitle()
);
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testPostRequestWithPOJO() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testPostRequestWithString() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::poststring[]
Flowable<HttpResponse<String>> call = client.exchange(
POST("/hello", "Hello John") // <1>
.contentType(MediaType.TEXT_PLAIN_TYPE)
.accept(MediaType.TEXT_PLAIN_TYPE), // <2>
String.class // <3>
);
// end::poststring[]
HttpResponse<String> response = call.blockingFirst();
Optional<String> message = response.getBody(String.class); // <2>
// check the status
assertEquals(
HttpStatus.CREATED,
response.getStatus() // <3>
);
// check the body
assertTrue(message.isPresent());
assertEquals(
"Hello John",
message.get()
);
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testRetrieveWithPOJO() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::jsonpojo[]
Flowable<Message> response = client.retrieve(
GET("/greet/John"), Message.class
);
assertEquals(
"Hello John",
response.blockingFirst().getText()
);
// end::jsonpojo[]
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testRetrieveWithHeaders() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::headers[]
Flowable<String> response = client.retrieve(
GET("/hello/John")
.header("X-My-Header", "SomeValue")
);
// end::headers[]
assertEquals(
"Hello John",
response.blockingFirst()
);
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testPostFormData() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
代码示例来源:origin: micronaut-projects/micronaut-examples
@BeforeClass
public static void setupServer() {
server = ApplicationContext.run(EmbeddedServer.class, Collections.singletonMap(
"consul.client.enabled", false
));
client = server
.getApplicationContext()
.createBean(HttpClient.class, server.getURL());
}
内容来源于网络,如有侵权,请联系作者删除!