io.micronaut.context.annotation.Bean Java Examples
The following examples show how to use
io.micronaut.context.annotation.Bean.
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
Source File: BeanAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 6 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { List<AnnotationValue<?>> newAnnotations = new ArrayList<>(3); final AnnotationValueBuilder<Bean> beanAnn = AnnotationValue.builder(Bean.class); final Optional<String> destroyMethod = annotation.get("destroyMethod", String.class); destroyMethod.ifPresent(s -> beanAnn.member("preDestroy", s)); newAnnotations.add(beanAnn.build()); newAnnotations.add(AnnotationValue.builder(DefaultScope.class) .value(Singleton.class) .build()); final String beanName = annotation.getValue(String.class).orElse(annotation.get("name", String.class).orElse(null)); if (StringUtils.isNotEmpty(beanName)) { newAnnotations.add(AnnotationValue.builder(Named.class).value(beanName).build()); } return newAnnotations; }
Example #2
Source File: GrpcServerChannel.java From micronaut-grpc with Apache License 2.0 | 6 votes |
/** * Constructs a managed server channel. * @param server The server * @param executorService The executor service * @param clientInterceptors The client interceptors * @return The channel */ @Singleton @Named(NAME) @Requires(beans = GrpcEmbeddedServer.class) @Bean(preDestroy = "shutdown") protected ManagedChannel serverChannel( GrpcEmbeddedServer server, @javax.inject.Named(TaskExecutors.IO) ExecutorService executorService, List<ClientInterceptor> clientInterceptors) { final ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forAddress( server.getHost(), server.getPort() ).executor(executorService); if (!server.getServerConfiguration().isSecure()) { builder.usePlaintext(); } if (CollectionUtils.isNotEmpty(clientInterceptors)) { builder.intercept(clientInterceptors); } return builder.build(); }
Example #3
Source File: GrpcServerChannel.java From micronaut-grpc with Apache License 2.0 | 6 votes |
/** * Constructs a managed server channel. * @param server The server * @param executorService The executor service * @param clientInterceptors The client interceptors * @return The channel */ @Singleton @Named(NAME) @Requires(beans = GrpcEmbeddedServer.class) @Bean(preDestroy = "shutdown") protected ManagedChannel serverChannel( GrpcEmbeddedServer server, @javax.inject.Named(TaskExecutors.IO) ExecutorService executorService, List<ClientInterceptor> clientInterceptors) { final ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forAddress( server.getHost(), server.getPort() ).executor(executorService); if (!server.getServerConfiguration().isSecure()) { builder.usePlaintext(); } if (CollectionUtils.isNotEmpty(clientInterceptors)) { builder.intercept(clientInterceptors); } return builder.build(); }
Example #4
Source File: GraphQLFactory.java From micronaut-graphql with Apache License 2.0 | 6 votes |
@Bean @Singleton public GraphQL graphQL(ResourceResolver resourceResolver, HelloDataFetcher helloDataFetcher) { // <2> SchemaParser schemaParser = new SchemaParser(); SchemaGenerator schemaGenerator = new SchemaGenerator(); // Parse the schema. TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry(); typeRegistry.merge(schemaParser.parse(new BufferedReader(new InputStreamReader( resourceResolver.getResourceAsStream("classpath:schema.graphqls").get())))); // Create the runtime wiring. RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring() .type("Query", typeWiring -> typeWiring .dataFetcher("hello", helloDataFetcher)) .build(); // Create the executable schema. GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring); // Return the GraphQL bean. return GraphQL.newGraphQL(graphQLSchema).build(); }
Example #5
Source File: GraphQLFactory.java From micronaut-graphql with Apache License 2.0 | 5 votes |
@Bean @Singleton public GraphQL graphQL(ResourceResolver resourceResolver, MessagesDataFetcher messagesDataFetcher, ChatDataFetcher chatDataFetcher, StreamDataFetcher streamDataFetcher) { SchemaParser schemaParser = new SchemaParser(); SchemaGenerator schemaGenerator = new SchemaGenerator(); // Parse the schema. TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry(); resourceResolver .getResourceAsStream("classpath:schema.graphqls") .ifPresent(s -> typeRegistry.merge(schemaParser.parse(new BufferedReader(new InputStreamReader(s))))); // Create the runtime wiring. RuntimeWiring runtimeWiring = RuntimeWiring .newRuntimeWiring() .scalar(ExtendedScalars.DateTime) .type("QueryRoot", typeWiring -> typeWiring .dataFetcher("messages", messagesDataFetcher)) .type("MutationRoot", typeWiring -> typeWiring .dataFetcher("chat", chatDataFetcher)) .type("SubscriptionRoot", typeWiring -> typeWiring .dataFetcher("stream", streamDataFetcher)) .build(); // Create the executable schema. GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring); // Return the GraphQL bean. return GraphQL.newGraphQL(graphQLSchema).build(); }
Example #6
Source File: StackdriverSenderFactory.java From micronaut-gcp with Apache License 2.0 | 5 votes |
/** * @return A GRPC channel to use to send traces. */ @Singleton @Bean(preDestroy = "shutdownNow") @Named("stackdriverTraceSenderChannel") protected @Nonnull ManagedChannel stackdriverTraceSenderChannel() { UserAgentHeaderProvider userAgentHeaderProvider = new UserAgentHeaderProvider("trace"); return ManagedChannelBuilder.forTarget(TRACE_TARGET) .userAgent(userAgentHeaderProvider.getUserAgent()) .build(); }
Example #7
Source File: GrpcManagedChannelFactory.java From micronaut-grpc with Apache License 2.0 | 5 votes |
/** * Builds a managed channel for the given target. * @param target The target * @return The channel */ @Bean @Primary protected ManagedChannel managedChannel(@Parameter String target) { final NettyChannelBuilder nettyChannelBuilder = beanContext.createBean(NettyChannelBuilder.class, target); return nettyChannelBuilder.build(); }
Example #8
Source File: GrpcServerTracingInterceptorFactory.java From micronaut-grpc with Apache License 2.0 | 5 votes |
/** * The server interceptor. * @param configuration The configuration * @return The server interceptor */ @Requires(beans = GrpcServerTracingInterceptorConfiguration.class) @Singleton @Bean protected @Nonnull ServerInterceptor serverTracingInterceptor(@Nonnull GrpcServerTracingInterceptorConfiguration configuration) { return configuration.getBuilder().build(); }
Example #9
Source File: PgClientFactory.java From micronaut-sql with Apache License 2.0 | 5 votes |
/** * @return client A pool of connections. */ @Singleton @Bean(preDestroy = "close") public PgPool client() { if (this.vertx == null) { return createClient(); } else { return createClient(vertx); } }
Example #10
Source File: MySQLClientFactory.java From micronaut-sql with Apache License 2.0 | 5 votes |
/** * @return client A pool of connections. */ @Singleton @Bean(preDestroy = "close") public MySQLPool client() { if (this.vertx == null) { return createClient(); } else { return createClient(vertx); } }
Example #11
Source File: ConsumerExecutorServiceConfig.java From micronaut-kafka with Apache License 2.0 | 5 votes |
/** * @return The executor configurations */ @Singleton @Bean @Named(TaskExecutors.MESSAGE_CONSUMER) ExecutorConfiguration configuration() { return UserExecutorConfiguration.of(ExecutorType.FIXED, 75); }
Example #12
Source File: GraphQLFactory.java From micronaut-graphql with Apache License 2.0 | 5 votes |
@Bean @Singleton public GraphQL graphQL(ToDoService toDoService) { // Create the executable schema. GraphQLSchema graphQLSchema = new GraphQLSchemaGenerator() .withOperationsFromSingleton(toDoService) .generate(); // Return the GraphQL bean. return GraphQL.newGraphQL(graphQLSchema).build(); }
Example #13
Source File: GraphQLFactory.java From micronaut-graphql with Apache License 2.0 | 5 votes |
@Bean @Singleton public GraphQL graphQL(ResourceResolver resourceResolver, ToDosDataFetcher toDosDataFetcher, CreateToDoDataFetcher createToDoDataFetcher, CompleteToDoDataFetcher completeToDoDataFetcher, DeleteToDoDataFetcher deleteToDoDataFetcher) { SchemaParser schemaParser = new SchemaParser(); SchemaGenerator schemaGenerator = new SchemaGenerator(); // Parse the schema. TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry(); typeRegistry.merge(schemaParser.parse(new BufferedReader(new InputStreamReader( resourceResolver.getResourceAsStream("classpath:schema.graphqls").get())))); // Create the runtime wiring. RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring() .type("Query", typeWiring -> typeWiring .dataFetcher("toDos", toDosDataFetcher)) .type("Mutation", typeWiring -> typeWiring .dataFetcher("createToDo", createToDoDataFetcher) .dataFetcher("completeToDo", completeToDoDataFetcher) .dataFetcher("deleteToDo", deleteToDoDataFetcher)) .build(); // Create the executable schema. GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring); // Return the GraphQL bean. return GraphQL.newGraphQL(graphQLSchema).build(); }
Example #14
Source File: GrpcClientTracingInterceptorFactory.java From micronaut-grpc with Apache License 2.0 | 5 votes |
/** * The client interceptor. * @param configuration The configuration * @return The client interceptor */ @Requires(beans = GrpcClientTracingInterceptorConfiguration.class) @Singleton @Bean protected @Nonnull ClientInterceptor clientTracingInterceptor(@Nonnull GrpcClientTracingInterceptorConfiguration configuration) { return configuration.getBuilder().build(); }
Example #15
Source File: GraphQLFactory.java From micronaut-graphql with Apache License 2.0 | 5 votes |
@Bean @Singleton public GraphQL graphQL(ToDoQueryResolver toDoQueryResolver, ToDoMutationResolver toDoMutationResolver) { // Parse the schema. SchemaParserBuilder builder = SchemaParser.newParser() .file("schema.graphqls") .resolvers(toDoQueryResolver, toDoMutationResolver); // Create the executable schema. GraphQLSchema graphQLSchema = builder.build().makeExecutableSchema(); // Return the GraphQL bean. return GraphQL.newGraphQL(graphQLSchema).build(); }
Example #16
Source File: GrpcClientTracingInterceptorFactory.java From micronaut-grpc with Apache License 2.0 | 5 votes |
/** * The client interceptor. * @param configuration The configuration * @return The client interceptor */ @Requires(beans = GrpcClientTracingInterceptorConfiguration.class) @Singleton @Bean protected @Nonnull ClientInterceptor clientTracingInterceptor(@Nonnull GrpcClientTracingInterceptorConfiguration configuration) { return configuration.getBuilder().build(); }
Example #17
Source File: GrpcManagedChannelFactory.java From micronaut-grpc with Apache License 2.0 | 5 votes |
/** * Builds a managed channel for the given target. * @param target The target * @return The channel */ @Bean @Primary protected ManagedChannel managedChannel(@Parameter String target) { final NettyChannelBuilder nettyChannelBuilder = beanContext.createBean(NettyChannelBuilder.class, target); return nettyChannelBuilder.build(); }
Example #18
Source File: GrpcServerTracingInterceptorFactory.java From micronaut-grpc with Apache License 2.0 | 5 votes |
/** * The server interceptor. * @param configuration The configuration * @return The server interceptor */ @Requires(beans = GrpcServerTracingInterceptorConfiguration.class) @Singleton @Bean protected @Nonnull ServerInterceptor serverTracingInterceptor(@Nonnull GrpcServerTracingInterceptorConfiguration configuration) { return configuration.getBuilder().build(); }
Example #19
Source File: ComponentAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 5 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final Optional<String> beanName = annotation.getValue(String.class); List<AnnotationValue<?>> mappedAnnotations = new ArrayList<>(2); mappedAnnotations.add(AnnotationValue.builder(Bean.class).build()); mappedAnnotations.add(AnnotationValue.builder(DefaultScope.class) .value(Singleton.class) .build()); beanName.ifPresent(s -> mappedAnnotations.add(AnnotationValue.builder(Named.class).value(s).build())); return mappedAnnotations; }
Example #20
Source File: PgClientFactory.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Bean @Singleton public PgClients pgClients(Vertx vertx) { List<PgClient> clients = new ArrayList<>(); for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) { clients.add(pgClient(vertx)); } return new PgClients(clients); }
Example #21
Source File: CredentialsAndRegionFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * @param environment The {@link Environment} * @return An {@link AwsCredentialsProviderChain} that attempts to read the values from the Micronaut environment * first, then delegates to {@link DefaultCredentialsProvider}. */ @Bean(preDestroy = "close") @Singleton public AwsCredentialsProviderChain awsCredentialsProvider(Environment environment) { return AwsCredentialsProviderChain.of( EnvironmentAwsCredentialsProvider.create(environment), DefaultCredentialsProvider.create() ); }
Example #22
Source File: UrlConnectionClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * Creates an {@link software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient} client if there are no other clients configured. * * @param configuration The URLConnection client configuration * @return An instance of {@link SdkHttpClient} */ @Bean(preDestroy = "close") @Singleton @Requires(missingBeans = SdkHttpClient.class) public SdkHttpClient urlConnectionClient(UrlConnectionClientConfiguration configuration) { return doCreateClient(configuration); }
Example #23
Source File: ApacheClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * @param configuration The Apache client configuration * @return An instance of {@link SdkHttpClient} */ @Bean(preDestroy = "close") @Singleton @Requires(property = UrlConnectionClientFactory.HTTP_SERVICE_IMPL, value = APACHE_SDK_HTTP_SERVICE) public SdkHttpClient systemPropertyClient(ApacheClientConfiguration configuration) { return doCreateClient(configuration); }
Example #24
Source File: ApacheClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * @param configuration The Apache client configuration * @return An instance of {@link SdkHttpClient} */ @Bean(preDestroy = "close") @Singleton @Requires(property = UrlConnectionClientFactory.HTTP_SERVICE_IMPL, notEquals = UrlConnectionClientFactory.URL_CONNECTION_SDK_HTTP_SERVICE) public SdkHttpClient apacheClient(ApacheClientConfiguration configuration) { return doCreateClient(configuration); }
Example #25
Source File: NettyClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * @param configuration The Netty client configuration * @return an instance of {@link SdkAsyncHttpClient} */ @Bean(preDestroy = "close") @Singleton @Requires(property = ASYNC_SERVICE_IMPL, value = NETTY_SDK_ASYNC_HTTP_SERVICE) public SdkAsyncHttpClient systemPropertyClient(NettyClientConfiguration configuration) { return doCreateClient(configuration); }
Example #26
Source File: SesClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
@Override @Bean(preDestroy = "close") @Singleton @Requires(beans = SdkAsyncHttpClient.class) public SesAsyncClient asyncClient(SesAsyncClientBuilder builder) { return super.asyncClient(builder); }
Example #27
Source File: S3ClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
@Override @Bean(preDestroy = "close") @Singleton @Requires(beans = SdkAsyncHttpClient.class) public S3AsyncClient asyncClient(S3AsyncClientBuilder builder) { return super.asyncClient(builder); }
Example #28
Source File: SqsClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
@Override @Bean(preDestroy = "close") @Singleton @Requires(beans = SdkAsyncHttpClient.class) public SqsAsyncClient asyncClient(SqsAsyncClientBuilder builder) { return super.asyncClient(builder); }
Example #29
Source File: SnsClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
@Override @Bean(preDestroy = "close") @Singleton @Requires(beans = SdkAsyncHttpClient.class) public SnsAsyncClient asyncClient(SnsAsyncClientBuilder builder) { return super.asyncClient(builder); }
Example #30
Source File: S3ClientFactory.java From micronaut-aws with Apache License 2.0 | 4 votes |
@Override @Bean(preDestroy = "close") @Singleton public S3Client syncClient(S3ClientBuilder builder) { return super.syncClient(builder); }