io.micronaut.context.annotation.Requires Java Examples
The following examples show how to use
io.micronaut.context.annotation.Requires.
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: StackdriverSenderFactory.java From micronaut-gcp with Apache License 2.0 | 6 votes |
/** * The {@link StackdriverSender} bean. * @param cloudConfiguration The google cloud configuration * @param credentials The credentials * @param channel The channel to use * @return The sender */ @RequiresGoogleProjectId @Requires(classes = StackdriverSender.class) @Singleton protected @Nonnull Sender stackdriverSender( @Nonnull GoogleCloudConfiguration cloudConfiguration, @Nonnull GoogleCredentials credentials, @Nonnull @Named("stackdriverTraceSenderChannel") ManagedChannel channel) { GoogleCredentials traceCredentials = credentials.createScoped(Arrays.asList(TRACE_SCOPE.toString())); return StackdriverSender.newBuilder(channel) .projectId(cloudConfiguration.getProjectId()) .callOptions(CallOptions.DEFAULT .withCallCredentials(MoreCallCredentials.from(traceCredentials))) .build(); }
Example #2
Source File: ConditionalOnPropertyAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 6 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final String[] propertyNames = annotation.getValue(String[].class).orElseGet(() -> annotation.get("name", String[].class).orElse(null)); if (propertyNames != null) { final String prefix = annotation.get("prefix", String.class).orElse(null); final boolean matchIfMissing = annotation.get("matchIfMissing", boolean.class).orElse(false); final String havingValue = annotation.get("havingValue", String.class).orElse(null); List<AnnotationValue<?>> annotationValues = new ArrayList<>(propertyNames.length); for (String propertyName : propertyNames) { if (prefix != null) { propertyName = prefix + "." + propertyName; } final AnnotationValueBuilder<Requires> builder = AnnotationValue.builder(Requires.class); builder.member(matchIfMissing ? "missingProperty" : "property", propertyName); if (havingValue != null) { builder.value(havingValue); } annotationValues.add(builder.build()); } return annotationValues; } return Collections.emptyList(); }
Example #3
Source File: ConditionalOnSingleCandidateAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 6 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final AnnotationClassValue annotationClassValue = annotation.getValue(AnnotationClassValue.class).orElseGet(() -> annotation.get("type", String.class).map(AnnotationClassValue::new).orElse(null) ); if (annotationClassValue != null) { return Arrays.asList( AnnotationValue.builder(Requires.class) .member("condition", new AnnotationClassValue<>( "io.micronaut.spring.boot.condition.RequiresSingleCandidateCondition" )) .build(), AnnotationValue.builder("io.micronaut.spring.boot.condition.RequiresSingleCandidate") .member("value", annotationClassValue) .build() ); } return Collections.emptyList(); }
Example #4
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 #5
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 #6
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 #7
Source File: ProfileAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 5 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { Optional<String[]> value = annotation.getValue(String[].class); return value.<List<AnnotationValue<?>>>map(strings -> Collections.singletonList( AnnotationValue.builder(Requires.class) .member("env", strings).build() )).orElse(Collections.emptyList()); }
Example #8
Source File: GrpcNameResolverFactory.java From micronaut-grpc with Apache License 2.0 | 5 votes |
/** * A GRPC name resolver factory that integrates with Micronaut's discovery client. * @param discoveryClient The discovery client * @param serviceInstanceLists The service instance list * @return The name resolver */ @Singleton @Requires(beans = DiscoveryClient.class) @Requires(property = ENABLED, value = StringUtils.TRUE, defaultValue = StringUtils.FALSE) protected NameResolver.Factory nameResolverFactory( DiscoveryClient discoveryClient, List<ServiceInstanceList> serviceInstanceLists) { return new GrpcNameResolverProvider(discoveryClient, serviceInstanceLists); }
Example #9
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 #10
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 #11
Source File: DatasourceFactory.java From micronaut-sql with Apache License 2.0 | 5 votes |
/** * Method to create a metadata object that allows pool value lookup for each datasource object. * * @param dataSource The datasource * @return a {@link TomcatDataSourcePoolMetadata} */ @EachBean(DataSource.class) @Requires(beans = {DatasourceConfiguration.class}) public TomcatDataSourcePoolMetadata tomcatPoolDataSourceMetadataProvider( DataSource dataSource) { TomcatDataSourcePoolMetadata dataSourcePoolMetadata = null; DataSource resolved = dataSourceResolver.resolve(dataSource); if (resolved instanceof org.apache.tomcat.jdbc.pool.DataSource) { dataSourcePoolMetadata = new TomcatDataSourcePoolMetadata((org.apache.tomcat.jdbc.pool.DataSource) resolved); } return dataSourcePoolMetadata; }
Example #12
Source File: GrpcNameResolverFactory.java From micronaut-grpc with Apache License 2.0 | 5 votes |
/** * A GRPC name resolver factory that integrates with Micronaut's discovery client. * @param discoveryClient The discovery client * @param serviceInstanceLists The service instance list * @return The name resolver */ @Singleton @Requires(beans = DiscoveryClient.class) @Requires(property = ENABLED, value = StringUtils.TRUE, defaultValue = StringUtils.FALSE) protected NameResolver.Factory nameResolverFactory( DiscoveryClient discoveryClient, List<ServiceInstanceList> serviceInstanceLists) { return new GrpcNameResolverProvider(discoveryClient, serviceInstanceLists); }
Example #13
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 #14
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 #15
Source File: ConditionalOnNotWebApplicationAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 5 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { return Collections.singletonList( AnnotationValue.builder(Requires.class) .member("missingBeans", new AnnotationClassValue<>(EmbeddedServer.class)) .build() ); }
Example #16
Source File: ConditionalOnWebApplicationAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 5 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { return Collections.singletonList( AnnotationValue.builder(Requires.class) .member("beans", new AnnotationClassValue<>(EmbeddedServer.class)) .build() ); }
Example #17
Source File: GoogleCredentialsFactory.java From micronaut-gcp with Apache License 2.0 | 5 votes |
/** * Method used to return the default {@link GoogleCredentials} and provide it as a bean. * * It will determine which credential in the following way: * <ol> * <li>If <pre>gcp.credentials.location</pre> is specified, use its location</li> * <li>Otherwise, if <pre>gcp.credentials.encodedKey</pre> is specified, decode it and use its content</li> * <li>None of the 2 properties were specified, use Application Default credential resolution. See * <a href="https://github.com/googleapis/google-cloud-java#authentication">Google Cloud Java authentication</a>. * This will resolve credential in the following order: * <ol> * <li>The credentials file pointed to by the <pre>GOOGLE_APPLICATION_CREDENTIALS</pre> environment variable</li> * <li>Credentials provided by the Google Cloud SDK <pre>gcloud auth application-default login</pre> command</li> * <li>Google App Engine built-in credentials when running inside of Google App Engine</li> * <li>Google Cloud Shell built-in credentials when running inside of Google Cloud Shell</li> * <li>Google Compute Engine built-in credentials when running inside of Google Compute Engine or Kubernetes Engine</li> * </ol> * </li> * </ol> * * @return The {@link GoogleCredentials} * @throws IOException An exception if an error occurs */ @Requires(missingBeans = GoogleCredentials.class) @Requires(classes = com.google.auth.oauth2.GoogleCredentials.class) @Primary @Singleton protected GoogleCredentials defaultGoogleCredentials() throws IOException { final List<String> scopes = configuration.getScopes().stream() .map(URI::toString).collect(Collectors.toList()); GoogleCredentials credentials; if (configuration.getLocation().isPresent() && configuration.getEncodedKey().isPresent()) { throw new ConfigurationException("Please specify only one of gcp.credentials.location or gcp.credentials.encodedKey"); } else if (configuration.getLocation().isPresent()) { LOG.info("Google Credentials from gcp.credentials.location = " + configuration.getLocation()); FileInputStream fis = new FileInputStream(configuration.getLocation().get()); credentials = GoogleCredentials.fromStream(fis); fis.close(); } else if (configuration.getEncodedKey().isPresent()) { LOG.info("Google Credentials from gcp.credentials.encodedKey"); Base64.Decoder decoder = Base64.getDecoder(); byte[] bytes = decoder.decode(configuration.getEncodedKey().get()); ByteArrayInputStream is = new ByteArrayInputStream(bytes); credentials = GoogleCredentials.fromStream(is); is.close(); } else { LOG.info("Google Credentials from Application Default Credentials"); credentials = GoogleCredentials.getApplicationDefault(); } return credentials.createScoped(scopes); }
Example #18
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 #19
Source File: StackdriverSenderFactory.java From micronaut-gcp with Apache License 2.0 | 5 votes |
/** * A {@link BeanCreatedEventListener} that modifies the brave trace configuration for Stackdriver compatibility. * @return The {@link BeanCreatedEventListener} */ @Singleton @Requires(classes = StackdriverSender.class) protected @Nonnull BeanCreatedEventListener<BraveTracerConfiguration> braveTracerConfigurationBeanCreatedEventListener() { return (configuration) -> { BraveTracerConfiguration configurationBean = configuration.getBean(); configurationBean.getTracingBuilder() .traceId128Bit(true) .supportsJoin(false); return configurationBean; }; }
Example #20
Source File: StackdriverSenderFactory.java From micronaut-gcp with Apache License 2.0 | 5 votes |
/** * A custom {@link AsyncReporter} that uses {@link StackdriverEncoder#V2}. * * @param configuration The configuration * @return The bean. */ @Singleton @Requires(classes = StackdriverSender.class) @Requires(beans = AsyncReporterConfiguration.class) public AsyncReporter<Span> stackdriverReporter(@Nonnull AsyncReporterConfiguration configuration) { return configuration.getBuilder() .build(StackdriverEncoder.V2); }
Example #21
Source File: AWSLambdaAsyncClientFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * The client returned from a builder. * @return client object */ @Requires(beans = AWSLambdaConfiguration.class) @Singleton AWSLambdaAsync awsLambdaAsyncClient() { AWSLambdaAsyncClientBuilder builder = configuration.getBuilder(); return builder.build(); }
Example #22
Source File: AwsObjectMapperFactory.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * @return a new {@link ObjectMapper} */ @Singleton @Named("aws") @Requires(property = AWSConfiguration.PREFIX + "." + MicronautAwsProxyConfiguration.PREFIX + ".shared-object-mapper", value = "false") public ObjectMapper objectMapper() { return new ObjectMapper(); }
Example #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
Source File: S3ClientFactory.java From micronaut-aws with Apache License 2.0 | 4 votes |
@Override @Singleton @Requires(beans = SdkAsyncHttpClient.class) public S3AsyncClientBuilder asyncBuilder(SdkAsyncHttpClient httpClient) { return super.asyncBuilder(httpClient); }
Example #30
Source File: SnsClientFactory.java From micronaut-aws with Apache License 2.0 | 4 votes |
@Override @Singleton @Requires(beans = SdkAsyncHttpClient.class) public SnsAsyncClientBuilder asyncBuilder(SdkAsyncHttpClient httpClient) { return super.asyncBuilder(httpClient); }