Java Code Examples for org.springframework.context.annotation.AnnotationConfigApplicationContext#registerBean()

The following examples show how to use org.springframework.context.annotation.AnnotationConfigApplicationContext#registerBean() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Before
public void setup() {
	ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
	resolvers.addCustomResolver(new CustomArgumentResolver());
	resolvers.addCustomResolver(new CustomSyncArgumentResolver());

	ServerCodecConfigurer codecs = ServerCodecConfigurer.create();
	codecs.customCodecs().decoder(new ByteArrayDecoder());
	codecs.customCodecs().decoder(new ByteBufferDecoder());

	AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
	applicationContext.registerBean(TestControllerAdvice.class);
	applicationContext.refresh();

	this.methodResolver = new ControllerMethodResolver(
			resolvers, ReactiveAdapterRegistry.getSharedInstance(), applicationContext, codecs.getReaders());

	Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::handle).method();
	this.handlerMethod = new HandlerMethod(new TestController(), method);
}
 
Example 2
@Before
public void setup() {
	ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
	resolvers.addCustomResolver(new CustomArgumentResolver());
	resolvers.addCustomResolver(new CustomSyncArgumentResolver());

	ServerCodecConfigurer codecs = ServerCodecConfigurer.create();
	codecs.customCodecs().decoder(new ByteArrayDecoder());
	codecs.customCodecs().decoder(new ByteBufferDecoder());

	AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
	applicationContext.registerBean(TestControllerAdvice.class);
	applicationContext.refresh();

	this.methodResolver = new ControllerMethodResolver(
			resolvers, ReactiveAdapterRegistry.getSharedInstance(), applicationContext, codecs.getReaders());

	Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::handle).method();
	this.handlerMethod = new HandlerMethod(new TestController(), method);
}
 
Example 3
Source Project: webanno   File: Plugin.java    License: Apache License 2.0 6 votes vote down vote up
protected ApplicationContext createApplicationContext()
{
    Plugin springPlugin = (Plugin) getWrapper().getPlugin();
    
    // Create an application context for this plugin using Spring annotated classes starting
    // with the plugin class
    AnnotationConfigApplicationContext pluginContext = new AnnotationConfigApplicationContext();
    pluginContext
            .setResourceLoader(new DefaultResourceLoader(getWrapper().getPluginClassLoader()));
    pluginContext.registerBean(ExportedComponentPostProcessor.class);
    pluginContext.register(springPlugin.getSources().stream().toArray(Class[]::new));

    // Attach the plugin application context to the main application context such that it can
    // access its beans for auto-wiring
    ApplicationContext parent = ((PluginManager) getWrapper().getPluginManager())
            .getApplicationContext();
    pluginContext.setParent(parent);

    // Initialize the context
    pluginContext.refresh();
    
    
    return pluginContext;
}
 
Example 4
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    PostRepository posts = new PostRepository();
    PostHandler postHandler = new PostHandler(posts);
    Routes routesBean = new Routes(postHandler);

    context.registerBean(PostRepository.class, () -> posts);
    context.registerBean(PostHandler.class, () -> postHandler);
    context.registerBean(Routes.class, () -> routesBean);
    context.registerBean(WebHandler.class, () -> RouterFunctions.toWebHandler(routesBean.routes(), HandlerStrategies.builder().build()));
    context.refresh();

    nettyServer(context).onDispose().block();
}
 
Example 5
private static ApplicationContext applicationContext(WebFilter... webFilters) {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	for(WebFilter filter : webFilters) {
		context.registerBean(WebFilter.class, () -> filter);
	}
	context.registerBean("webHandler", DispatcherHandler.class, () -> new DispatcherHandler());
	context.registerBean(HandlerMapping.class, () -> RouterFunctions.toHandlerMapping(request -> Mono.just(r -> ServerResponse.ok().build())));
	context.registerBean(HandlerAdapter.class, () -> new HandlerFunctionAdapter());
	context.registerBean(HandlerResultHandler.class, () -> new ServerResponseResultHandler());
	context.refresh();

	return context;
}
 
Example 6
@Override
protected AnnotationConfigApplicationContext newClient(int port) {
	AnnotationConfigApplicationContext result = new AnnotationConfigApplicationContext();
	URI baseUrl = URI.create("http://127.0.0.1:" + server.getPort());
	result.registerBean(HttpTracing.class, () -> httpTracing);
	result.registerBean(CurrentTraceContext.class,
			() -> httpTracing.tracing().currentTraceContext());
	result.registerBean(HttpClient.class, () -> testHttpClient(baseUrl));
	result.registerBean(URI.class, () -> baseUrl);
	result.register(componentClasses);
	result.refresh();
	return result;
}
 
Example 7
protected Retrofit buildAndSave(RetrofitContext context, Retrofit.Builder builder) {
	Retrofit retrofit = builder.build();

	// add retrofit to this.names context as a bean
	AnnotationConfigApplicationContext applicationContext = context.getContext(this.name);
	applicationContext.registerBean(Retrofit.class, () -> retrofit);
	return retrofit;
}
 
Example 8
private void customizeProjectGenerationContext(AnnotationConfigApplicationContext context,
		InitializrMetadata metadata) {
	context.setParent(this.parentApplicationContext);
	context.registerBean(InitializrMetadata.class, () -> metadata);
	context.registerBean(BuildItemResolver.class, () -> new MetadataBuildItemResolver(metadata,
			context.getBean(ProjectDescription.class).getPlatformVersion()));
	context.registerBean(MetadataProjectDescriptionCustomizer.class,
			() -> new MetadataProjectDescriptionCustomizer(metadata));
}