Skip to content

Latest commit

 

History

History
86 lines (68 loc) · 1.88 KB

java-spring-config.md

File metadata and controls

86 lines (68 loc) · 1.88 KB

Java-Spring-Config.Md


Attributes:

At instance level:

@Component
public class MyBean {
    @Value("${name}")
    private String name;
}

At interface level:

@FeignClient(value = "oidcClient", url="${feign.client.config.oidc.root}")
public interface OidcClient {
}

Changing the prefix and using validators:

@ConfigurationProperties(prefix="acme")
@Validated
public class AcmeProperties {
	@NotNull
	private InetAddress remoteAddress;
}

Using another file in classpath:

@Component
@PropertySource("classpath:global.properties")
public class GlobalProperties {

    @Value("${thread-pool}")
    private int threadPool;

    @Value("${email}")
    private String email;
}

Getting config from another class: ??

@Configuration
@EnableConfigurationProperties(AcmeProperties.class)
public class MyConfiguration {
}

Configuration location:

file:./custom-config/
classpath:custom-config/
file:./config/
file:./
classpath:/config/
classpath:/

Loaded properties:

Put a break-point in PropertySourcesPropertyResolver line 81. The sources and extracted values could be seen in propertySource.source. These are the default provided sources:

  1. "MapPropertySource {name='Inlined Test Properties'}"
  2. "MapPropertySource {name='systemProperties'}"
  3. "SystemEnvironmentPropertySource {name='systemEnvironment'}"
  4. "RandomValuePropertySource {name='random'}"
  5. "ConfigurationPropertySources {name='applicationConfigurationProperties'}"
    • applicationConfig: [classpath:/application.yml]
  6. "MapPropertySource {name='springCloudClientHostInfo'}"
  7. "MapPropertySource {name='defaultProperties'}"

----------------------------------------- 2018-06-30 04:52:46