Java Code Examples for org.springframework.boot.context.properties.bind.Binder#get()
The following examples show how to use
org.springframework.boot.context.properties.bind.Binder#get() .
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: BrpcProperties.java From brpc-java with Apache License 2.0 | 6 votes |
public BrpcConfig getServiceConfig(Class<?> serviceInterface) { BrpcConfig brpcConfig = new BrpcConfig(global); if (brpcConfig.getClient() == null) { brpcConfig.setClient(new RpcClientConfig()); } if (brpcConfig.getServer() == null) { brpcConfig.setServer(new RpcServerConfig()); } if (brpcConfig.getNaming() == null) { brpcConfig.setNaming(new RpcNamingConfig()); } String prefix = "brpc.custom." + normalizeName(serviceInterface.getName()) + "."; Binder binder = Binder.get(environment); binder.bind(prefix + "client", Bindable.ofInstance(brpcConfig.getClient())); binder.bind(prefix + "server", Bindable.ofInstance(brpcConfig.getServer())); binder.bind(prefix + "naming", Bindable.ofInstance(brpcConfig.getNaming())); rewriteMap(brpcConfig.getNaming().getExtra()); return brpcConfig; }
Example 2
Source File: NacosBootConfigurationPropertiesBinder.java From nacos-spring-boot-project with Apache License 2.0 | 6 votes |
@Override protected void doBind(Object bean, String beanName, String dataId, String groupId, String configType, NacosConfigurationProperties properties, String content, ConfigService configService) { String name = "nacos-bootstrap-" + beanName; NacosPropertySource propertySource = new NacosPropertySource(name, dataId, groupId, content, configType); environment.getPropertySources().addLast(propertySource); Binder binder = Binder.get(environment); ResolvableType type = getBeanType(bean, beanName); Bindable<?> target = Bindable.of(type).withExistingValue(bean); binder.bind(properties.prefix(), target); publishBoundEvent(bean, beanName, dataId, groupId, properties, content, configService); publishMetadataEvent(bean, beanName, dataId, groupId, properties); environment.getPropertySources().remove(name); }
Example 3
Source File: CamelSSLAutoConfiguration.java From camel-spring-boot with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) { Binder binder = Binder.get(context.getEnvironment()); Map<String, Object> sslProperties = binder.bind("camel.ssl.config", Bindable.mapOf(String.class, Object.class)).orElse(Collections.emptyMap()); ConditionMessage.Builder message = ConditionMessage.forCondition("camel.ssl.config"); if (sslProperties.size() > 0) { return ConditionOutcome.match(message.because("enabled")); } return ConditionOutcome.noMatch(message.because("not enabled")); }
Example 4
Source File: FastDepRedisRegister.java From fastdep with Apache License 2.0 | 5 votes |
/** * init environment * * @param environment environment */ @Override public void setEnvironment(Environment environment) { this.env = environment; // bing binder binder = Binder.get(this.env); }
Example 5
Source File: FastDepDataSourceRegister.java From fastdep with Apache License 2.0 | 5 votes |
/** * init environment * * @param environment environment */ @Override public void setEnvironment(Environment environment) { this.env = environment; // bing binder binder = Binder.get(this.env); }
Example 6
Source File: NacosConfigPropertiesUtils.java From nacos-spring-boot-project with Apache License 2.0 | 5 votes |
public static NacosConfigProperties buildNacosConfigProperties( ConfigurableEnvironment environment) { NacosConfigProperties nacosConfigProperties = new NacosConfigProperties(); Binder binder = Binder.get(environment); ResolvableType type = ResolvableType.forClass(NacosConfigProperties.class); Bindable<?> target = Bindable.of(type).withExistingValue(nacosConfigProperties); binder.bind(NacosConfigConstants.PREFIX, target); logger.info("nacosConfigProperties : {}", nacosConfigProperties); return nacosConfigProperties; }
Example 7
Source File: OAuth2ResourceServerConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth ResourceServer Condition"); Environment environment = context.getEnvironment(); if (!(environment instanceof ConfigurableEnvironment)) { return ConditionOutcome.noMatch(message.didNotFind("A ConfigurableEnvironment").atAll()); } if (hasOAuthClientId(environment)) { return ConditionOutcome.match(message.foundExactly("client-id property")); } Binder binder = Binder.get(environment); String prefix = "security.oauth2.resource."; if (binder.bind(prefix + "jwt", STRING_OBJECT_MAP).isBound()) { return ConditionOutcome.match(message.foundExactly("JWT resource configuration")); } if (binder.bind(prefix + "jwk", STRING_OBJECT_MAP).isBound()) { return ConditionOutcome.match(message.foundExactly("JWK resource configuration")); } if (StringUtils.hasText(environment.getProperty(prefix + "user-info-uri"))) { return ConditionOutcome.match(message.foundExactly("user-info-uri property")); } if (StringUtils.hasText(environment.getProperty(prefix + "token-info-uri"))) { return ConditionOutcome.match(message.foundExactly("token-info-uri property")); } if (ClassUtils.isPresent(AUTHORIZATION_ANNOTATION, null)) { if (AuthorizationServerEndpointsConfigurationBeanCondition.matches(context)) { return ConditionOutcome.match(message.found("class").items(AUTHORIZATION_ANNOTATION)); } } return ConditionOutcome .noMatch(message.didNotFind("client ID, JWT resource or authorization server").atAll()); }
Example 8
Source File: CompositeEnvironmentBeanFactoryPostProcessor.java From spring-cloud-config with Apache License 2.0 | 5 votes |
private <P extends EnvironmentRepositoryProperties> P bindProperties(int index, Class<P> propertiesClass, Environment environment) { Binder binder = Binder.get(environment); String environmentConfigurationPropertyName = String .format("spring.cloud.config.server.composite[%d]", index); P properties = binder.bindOrCreate(environmentConfigurationPropertyName, propertiesClass); properties.setOrder(index + 1); return properties; }
Example 9
Source File: InitializrAutoConfiguration.java From initializr with Apache License 2.0 | 5 votes |
private Cache determineCache(Environment environment, CacheManager cacheManager) { if (cacheManager != null) { Binder binder = Binder.get(environment); boolean cache = binder.bind("spring.mustache.cache", Boolean.class).orElse(true); if (cache) { return cacheManager.getCache("initializr.templates"); } } return new NoOpCache("templates"); }
Example 10
Source File: DataSourceFactory.java From Milkomeda with MIT License | 4 votes |
@Override public void setEnvironment(@NonNull Environment environment) { binder = Binder.get(environment); }
Example 11
Source File: DelegatingBeanDefinitionRegistrar.java From Milkomeda with MIT License | 4 votes |
@Override public void setEnvironment(@NonNull Environment environment) { binder = Binder.get(environment); }
Example 12
Source File: HierarchicalPropertiesEvaluator.java From camel-spring-boot with Apache License 2.0 | 4 votes |
private static boolean isEnabled(Environment environment, String prefix, boolean defaultValue) { String property = prefix.endsWith(".") ? prefix + "enabled" : prefix + ".enabled"; Binder binder = Binder.get(environment); return binder.bind(property, Bindable.of(Boolean.class)).orElse(defaultValue); }
Example 13
Source File: Application.java From liiklus with MIT License | 4 votes |
public static SpringApplication createSpringApplication(String[] args) { var environment = new StandardEnvironment(); environment.setDefaultProfiles("exporter", "gateway"); environment.getPropertySources().addFirst(new SimpleCommandLinePropertySource(args)); var pluginsDir = environment.getProperty("plugins.dir", String.class, "./plugins"); var pathMatcher = environment.getProperty("plugins.pathMatcher", String.class, "*.jar"); var pluginsRoot = Paths.get(pluginsDir).toAbsolutePath().normalize(); log.info("Loading plugins from '{}' with matcher: '{}'", pluginsRoot, pathMatcher); var pluginManager = new LiiklusPluginManager(pluginsRoot, pathMatcher); pluginManager.loadPlugins(); pluginManager.startPlugins(); var binder = Binder.get(environment); var application = new SpringApplication(Application.class) { @Override protected void load(ApplicationContext context, Object[] sources) { // We don't want the annotation bean definition reader } }; application.setWebApplicationType(WebApplicationType.REACTIVE); application.setApplicationContextClass(ReactiveWebServerApplicationContext.class); application.setEnvironment(environment); application.addInitializers( new StringCodecInitializer(false, true), new ResourceCodecInitializer(false), new ReactiveWebServerInitializer( binder.bind("server", ServerProperties.class).orElseGet(ServerProperties::new), binder.bind("spring.resources", ResourceProperties.class).orElseGet(ResourceProperties::new), binder.bind("spring.webflux", WebFluxProperties.class).orElseGet(WebFluxProperties::new), new NettyReactiveWebServerFactory() ), new GatewayConfiguration(), (GenericApplicationContext applicationContext) -> { applicationContext.registerBean("health", RouterFunction.class, () -> { return RouterFunctions.route() .GET("/health", __ -> ServerResponse.ok().bodyValue("OK")) .build(); }); applicationContext.registerBean(PluginManager.class, () -> pluginManager); } ); application.addInitializers( pluginManager.getExtensionClasses(ApplicationContextInitializer.class).stream() .map(it -> { try { return it.getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException(e); } }) .toArray(ApplicationContextInitializer[]::new) ); return application; }