id stringlengths 16 145 | text stringlengths 1 179k | title stringclasses 1
value |
|---|---|---|
spring_io/bootfeaturesexternal1_25_0.txt | By default, ` SpringApplication ` converts any command line option arguments
(that is, arguments starting with ` -- ` , such as ` --server.port=9000 ` ) to
a ` property ` and adds them to the Spring ` Environment ` . As mentioned
previously, command line properties always take precedence over other property
sources. | |
spring_io/bootfeaturesexternal_99_0.txt | Consider the following configuration: | |
spring_io/spring_io_10_32.txt | ConnectionDetails ` | Containers of type ` ElasticsearchContainer `
` FlywayConnectionDetails ` | Containers of type ` JdbcDatabaseContainer `
` JdbcConnectionDetails ` | Containers of type ` JdbcDatabaseContainer `
` KafkaConnectionDetails ` | Containers of type ` KafkaContainer ` or ` RedpandaContainer `
... | |
spring_io/bootfeaturesexternal_7_0.txt | import org.springframework.stereotype.*
import org.springframework.beans.factory.annotation.* | |
spring_io/bootfeaturesexternal1_248_0.txt | _@DurationUnit(ChronoUnit.SECONDS)_
private Duration sessionTimeout = Duration.ofSeconds(30); | |
spring_io/bootfeaturesexternal1_93_0.txt | Whereas, in the following example, the password is always set because it is
not attached to any profile, and it would have to be explicitly reset in all
other profiles as necessary: | |
spring_io/bootfeaturesexternal1_113_0.txt | private final Security security = new Security(); | |
spring_io/bootfeaturesexternal1_162_0.txt | As well as using ` @ConfigurationProperties ` to annotate a class, you can
also use it on public ` @Bean ` methods. Doing so can be particularly useful
when you want to bind properties to third-party components that are outside of
your control. | |
spring_io/bootfeaturesexternal_84_0.txt | server:
address: 192.168.1.100
---
spring:
profiles: development
server:
address: 127.0.0.1
---
spring:
profiles: production
server:
address: 192.168.1.120 | |
spring_io/spring_io_8_1.txt | : JsonDeserializer<MyObject>() {
@Throws(IOException::class, JsonProcessingException::class)
override fun deserialize(jsonParser: JsonParser, ctxt: DeserializationContext): MyObject {
val codec = jsonParser.codec
val tree = codec.readTree<JsonNode>(jsonParser)
... | |
spring_io/bootfeaturesexternal1_195_0.txt | Upper case format with underscore as the delimiter (see [ the section called
“Binding from Environment Variables” ](boot-features-external-
config.html#boot-features-external-config-relaxed-binding-from-environment-
variables "Binding from Environment Variables") ). | |
spring_io/bootfeaturesexternal_51_0.txt | If several profiles are specified, a last wins strategy applies. For example,
profiles specified by the ` spring.profiles.active ` property are added after
those configured via the ` SpringApplication ` API and therefore take
precedence. | |
spring_io/bootfeaturesexternal_6_0.txt | To provide a concrete example, suppose you develop a ` @Component ` that uses
a ` name ` property: | |
spring_io/bootfeaturesexternal_154_0.txt | //... | |
spring_io/spring_io_3_5.txt | g/myconfig ` file that you wish to
import as yaml. You can import it from your ` application.properties ` using
the following:
Properties
spring.config.import=file:/etc/config/myconfig[.yaml]
Yaml
spring:
config:
import: "file:/etc/config/myconfig[.yaml]"
#### 2.3.6. Usin... | |
spring_io/bootfeaturesexternal_87_0.txt | server:
port: 8000
---
spring:
profiles: default
security:
user:
password: weak | |
spring_io/bootfeaturesexternal1_282_0.txt | ![\[Tip\]](images/tip.png) | Tip
---|--- | |
spring_io/bootfeaturesexternal1_103_0.txt | ![\[Tip\]](images/tip.png) | Tip
---|--- | |
spring_io/bootfeaturesexternal1_168_0.txt | As an example, consider the following ` @ConfigurationProperties ` class: | |
spring_io/bootfeaturesexternal_76_0.txt | public List<String> getServers() {
return this.servers;
}
} | |
spring_io/bootfeaturesexternal1_138_0.txt | Finally, only standard Java Bean properties are considered and binding on
static properties is not supported. | |
spring_io/bootfeaturesexternal_47_0.txt | If you are running in a container then JNDI properties (in ` java:comp/env ` )
or servlet context initialization parameters can be used instead of, or as
well as, environment variables or system properties. | |
spring_io/spring_io_12_2.txt | o4j:5");
}
If you already have containers defined in this way, or you just prefer this
style, you can import these declaration classes rather than defining you
containers as ` @Bean ` methods. To do so, add the ` @ImportTestcontainers `
annotation to your test configuration class:
Java
im... | |
spring_io/spring_io_10_30.txt |
}
Kotlin
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@Configuration(proxyBeanMethods = false)
class MyWebConfiguration {
... | |
spring_io/bootfeaturesexternal1_118_0.txt | public Security getSecurity() { ... } | |
spring_io/spring_io_1_1.txt |
* 9.3.17. Auto-configured Spring WebFlux Tests
* 9.3.18. Auto-configured Spring GraphQL Tests
* 9.3.19. Auto-configured Data Cassandra Tests
* 9.3.20. Auto-configured Data Couchbase Tests
* 9.3.21. Auto-configured Data Elasticsearch Tests
* 9.3.22. Auto-configured Data JPA Tes... | |
spring_io/bootfeaturesexternal1_225_0.txt | acme:
list:
- name: my name
description: my description
---
spring:
profiles: dev
acme:
list:
- name: my another name | |
spring_io/bootfeaturesexternal1_139_0.txt | ![\[Tip\]](images/tip.png) | Tip
---|--- | |
spring_io/bootfeaturesexternal_185_0.txt | ### 24.7.4 @ConfigurationProperties Validation | |
spring_io/spring_io_2_6.txt | _ | It is often desirable to call ` setWebApplicationType(WebApplicationType.NONE) ` when using ` SpringApplication ` within a JUnit test.
---|---
### 1.9. Accessing Application Arguments
If you need to access the application arguments that were passed to `
SpringApplication.run(…) ` , you can inject a `
or... | |
spring_io/bootfeaturesexternal1_253_0.txt | public void setReadTimeout(Duration readTimeout) {
this.readTimeout = readTimeout;
} | |
spring_io/spring_io_13_7.txt | .
---|---
| |
spring_io/spring_io_3_12.txt | t it is in the ` com.example.app ` package, the bean name of the ` SomeProperties ` example above is ` some.properties-com.example.app.SomeProperties ` .
---|---
We recommend that ` @ConfigurationProperties ` only deal with the environment
and, in particular, does not inject other beans from the context. For co... | |
spring_io/bootfeaturesexternal_108_0.txt | import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; | |
spring_io/bootfeaturesexternal1_265_0.txt | _@DataSizeUnit(DataUnit.MEGABYTES)_
private DataSize bufferSize = DataSize.ofMegabytes(2); | |
spring_io/bootfeaturesexternal1_258_0.txt | ![\[Tip\]](images/tip.png) | Tip
---|--- | |
spring_io/bootfeaturesexternal1_76_0.txt | my:
servers:
- dev.example.com
- another.example.com | |
spring_io/bootfeaturesexternal_157_0.txt | Using ` @ConfigurationProperties ` also allows you to generate meta-data files
that can be used by IDEs to offer auto-completion for your own keys, see the [
Appendix B, _Configuration meta-data_ ](configuration-metadata.html
"Appendix B. Configuration meta-data") appendix for details. | |
spring_io/bootfeaturesexternal_33_0.txt | If you don’t like ` application.properties ` as the configuration file name
you can switch to another by specifying a ` spring.config.name ` environment
property. You can also refer to an explicit location using the `
spring.config.location ` environment property (comma-separated list of
directory locations, or file pa... | |
spring_io/bootfeaturesexternal_27_0.txt | ## 24.3 Application property files | |
spring_io/bootfeaturesexternal1_215_0.txt | Underscores cannot be used to replace the dashes in property names. If you
attempt to use ` SPRING_MAIN_LOG_STARTUP_INFO ` with the example above, no
value will be bound. | |
spring_io/bootfeaturesexternal1_222_0.txt | private final List<MyPojo> list = new ArrayList<>(); | |
spring_io/bootfeaturesexternal_50_0.txt | Profile-specific properties are loaded from the same locations as standard `
application.properties ` , with profile-specific files always overriding the
non-specific ones irrespective of whether the profile-specific files are
inside or outside your packaged jar. | |
spring_io/bootfeaturesexternal1_232_0.txt | private final Map<String, MyPojo> map = new HashMap<>(); | |
spring_io/spring_io_15_1.txt | EBhMCWFgxEjAQBgNVBAgMCVN0YXRlTmFtZTERMA8GA1UEBwwI\n\
...\n\
V0IJjcmYjEZbTvpjFKznvaFiOUv+8L7jHQ1/Yf+9c3C8gSjdUfv88m17pqYXd+Ds\n\
HEmfmNNjht130UyjNCITmLVXyy5p35vWmdf95U3uEbJSnNVtXH8qRmN9oK9mUpDb\n\
ngX6JBJI7fw7tXoqWSLHNiBODM88fUlQSho8\n\
-----END CERTIFICATE-----\n
Yaml
spring:
s... | |
spring_io/bootfeaturesexternal_135_0.txt | Some people use Project Lombok to add getters and setters automatically. Make
sure that Lombok doesn’t generate any particular constructor for such type as
it will be used automatically by the container to instantiate the object. | |
spring_io/bootfeaturesexternal_169_0.txt | public void setFirstName(String firstName) {
this.firstName = firstName;
} | |
spring_io/bootfeaturesexternal1_177_0.txt | Kebab case, which is recommended for use in ` .properties ` and ` .yml `
files. | |
spring_io/bootfeaturesexternal_163_0.txt | ### 24.7.2 Relaxed binding | |
spring_io/bootfeaturesexternal1_172_0.txt | public void setFirstName(String firstName) {
this.firstName = firstName;
} | |
spring_io/bootfeaturesexternal_4_0.txt | Spring Boot uses a very particular ` PropertySource ` order that is designed
to allow sensible overriding of values. Properties are considered in the
following order: | |
spring_io/bootfeaturesexternal1_78_0.txt | my.servers[0]=dev.example.com
my.servers[1]=another.example.com | |
spring_io/bootfeaturesexternal1_50_0.txt | If your application runs in a container, then JNDI properties (in `
java:comp/env ` ) or servlet context initialization parameters can be used
instead of, or as well as, environment variables or system properties. | |
spring_io/spring_io_5_4.txt | lt ` ${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz ` ).
` logging.logback.rollingpolicy.clean-history-on-start ` | ` LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START ` | Whether to clean the archive log files on startup.
` logging.logback.rollingpolicy.max-file-size ` | ` LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE ` | Maximum log fi... | |
spring_io/bootfeaturesexternal1_46_0.txt | This search ordering lets you specify default values in one configuration file
and then selectively override those values in another. You can provide default
values for your application in ` application.properties ` (or whatever other
basename you choose with ` spring.config.name ` ) in one of the default
locations. Th... | |
spring_io/bootfeaturesexternal1_29_0.txt | 1. A ` /config ` subdirectory of the current directory
2. The current directory
3. A classpath ` /config ` package
4. The classpath root | |
spring_io/bootfeaturesexternal1_70_0.txt | Spring Framework provides two convenient classes that can be used to load YAML
documents. The ` YamlPropertiesFactoryBean ` loads YAML as ` Properties ` and
the ` YamlMapFactoryBean ` loads YAML as a ` Map ` . | |
spring_io/bootfeaturesexternal_198_0.txt | You can also add a custom Spring ` Validator ` by creating a bean definition
called ` configurationPropertiesValidator ` . The ` @Bean ` method should be
declared ` static ` . The configuration properties validator is created very
early in the application’s lifecycle and declaring the ` @Bean ` method as
static allows ... | |
spring_io/bootfeaturesexternal_193_0.txt | _@Valid_
private final Security security = new Security(); | |
spring_io/bootfeaturesexternal1_158_0.txt | _@PostConstruct_
public void openConnection() {
Server server = new Server(this.properties.getRemoteAddress());
// ...
} | |
spring_io/bootfeaturesexternal_85_0.txt | In the example above, the ` server.address ` property will be ` 127.0.0.1 ` if
the ` development ` profile is active. If the ` development ` and ` production
` profiles are **not** enabled, then the value for the property will be `
192.168.1.100 ` . | |
spring_io/bootfeaturesexternal_24_0.txt | ## 24.2 Accessing command line properties | |
spring_io/bootfeaturesexternal1_94_0.txt | server:
port: 8000
spring:
security:
user:
password: weak | |
spring_io/bootfeaturesexternal_127_0.txt | public List<String> getRoles() { ... } | |
spring_io/spring_io_10_34.txt |
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
class MyEnvironmentTests {
@Test
void testPropertyS... | |
spring_io/spring_io_5_3.txt | k: false
### 4.8. Custom Log Configuration
The various logging systems can be activated by including the appropriate
libraries on the classpath and can be further customized by providing a
suitable configuration file in the root of the classpath or in a location
specified by the following Spring ` Environment ` prop... | |
spring_io/bootfeaturesexternal1_274_0.txt | The default unit is bytes and can be overridden using ` @DataSizeUnit ` as
illustrated in the sample above. | |
spring_io/bootfeaturesexternal1_125_0.txt | public String getPassword() { ... } | |
spring_io/bootfeaturesexternal_92_0.txt | YAML files can’t be loaded via the ` @PropertySource ` annotation. So in the
case that you need to load values that way, you need to use a properties file. | |
spring_io/bootfeaturesexternal1_6_0.txt | To provide a concrete example, suppose you develop a ` @Component ` that uses
a ` name ` property, as shown in the following example: | |
spring_io/bootfeaturesexternal1_179_0.txt | Standard camel case syntax. | |
spring_io/environmentvariables_7_0.txt | # Environment variables in Java and Spring boot | |
spring_io/bootfeaturesexternal1_150_0.txt | # application.yml | |
spring_io/bootfeaturesexternal_67_0.txt | Would be transformed into these properties: | |
spring_io/bootfeaturesexternal_25_0.txt | By default ` SpringApplication ` will convert any command line option
arguments (starting with ‘--’, e.g. ` --server.port=9000 ` ) to a ` property `
and add it to the Spring ` Environment ` . As mentioned above, command line
properties always take precedence over other property sources. | |
spring_io/bootfeaturesexternal_79_0.txt | my:
servers: dev.bar.com,foo.bar.com | |
spring_io/bootfeaturesexternal1_197_0.txt | System properties | |
spring_io/bootfeaturesexternal_166_0.txt | _@ConfigurationProperties(prefix="person")_
public class OwnerProperties { | |
spring_io/bootfeaturesexternal_89_0.txt | server:
port: 8000
security:
user:
password: weak | |
spring_io/spring_io_3_14.txt | ` contains a ` . ` . For example, binding ` a.b=c ` to `
Map<String, Object> ` will return a Map with the entry ` {"a"={"b"="c"}} `
whereas ` [a.b]=c ` will return a Map with the entry ` {"a.b"="c"} ` .
##### Binding From Environment Variables
Most operating systems impose strict rules around the names that can be u... | |
spring_io/bootfeaturesexternal_59_0.txt | ## 24.6 Using YAML instead of Properties | |
spring_io/spring_io_5_1.txt | are
written. By default, ` ERROR ` -level, ` WARN ` -level, and ` INFO ` -level
messages are logged. You can also enable a “debug” mode by starting your
application with a ` --debug ` flag.
$ java -jar myapp.jar --debug
__ | You can also specify ` debug=true ` in your ` application.properties ` .
--... | |
spring_io/bootfeaturesexternal1_126_0.txt | public void setPassword(String password) { ... } | |
spring_io/bootfeaturesexternal1_133_0.txt | The properties that map to ` @ConfigurationProperties ` classes available in
Spring Boot, which are configured via properties files, YAML files,
environment variables etc., are public API but the accessors (getters/setters)
of the class itself are not meant to be used directly. | |
spring_io/bootfeaturesexternal1_228_0.txt | acme:
list:
- name: my name
description: my description
- name: another name
description: another description
---
spring:
profiles: dev
acme:
list:
- name: my another name | |
spring_io/bootfeaturesexternal_147_0.txt | # application.yml | |
spring_io/bootfeaturesexternal1_292_0.txt | You can also add a custom Spring ` Validator ` by creating a bean definition
called ` configurationPropertiesValidator ` . The ` @Bean ` method should be
declared ` static ` . The configuration properties validator is created very
early in the application’s lifecycle, and declaring the ` @Bean ` method as
static lets t... | |
spring_io/bootfeaturesexternal1_199_0.txt | Standard list syntax using ` [ ] ` or comma-separated values | |
spring_io/spring_io_10_23.txt | ore.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest
import org.springframework.http.MediaType
import org.springframework.test.web.client.MockRestServ... | |
spring_io/bootfeaturesexternal1_42_0.txt | When custom config locations are configured by using ` spring.config.location
` , they replace the default locations. For example, if `
spring.config.location ` is configured with the value ` classpath:/custom-
config/,file:./custom-config/ ` , the search order becomes the following: | |
spring_io/bootfeaturesexternal_179_0.txt | ` PERSON_FIRST_NAME ` | |
spring_io/bootfeaturesexternal1_26_0.txt | If you do not want command line properties to be added to the ` Environment `
, you can disable them by using `
SpringApplication.setAddCommandLineProperties(false) ` . | |
spring_io/bootfeaturesexternal_9_0.txt | _@Value("${name}")_
private String name; | |
spring_io/spring_io_5_5.txt | ringProfile name="staging">
<!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>
<springProfile name="dev | staging">
<!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>
<springProfile name=... | |
spring_io/bootfeaturesexternal1_164_0.txt | _@ConfigurationProperties(prefix = "another")_
_@Bean_
public AnotherComponent anotherComponent() {
...
} | |
spring_io/bootfeaturesexternal1_213_0.txt | For example, the configuration property ` spring.main.log-startup-info ` would
be an environment variable named ` SPRING_MAIN_LOGSTARTUPINFO ` . | |
spring_io/bootfeaturesexternal1_128_0.txt | public void setRoles(List<String> roles) { ... } | |
spring_io/bootfeaturesexternal_199_0.txt | ![\[Tip\]](images/tip.png) | Tip
---|--- | |
spring_io/bootfeaturesexternal1_281_0.txt | // ... getters and setters | |
spring_io/bootfeaturesexternal1_269_0.txt | public DataSize getSizeThreshold() {
return this.sizeThreshold;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.