id stringlengths 16 145 | text stringlengths 1 179k | title stringclasses 1
value |
|---|---|---|
spring_io/bootfeaturesexternal1_264_0.txt | _@ConfigurationProperties("app.io")_
public class AppIoProperties { | |
spring_io/bootfeaturesexternal1_88_0.txt | In the preceding example, if the ` development ` profile is active, the `
server.address ` property is ` 127.0.0.1 ` . Similarly, if the ` production `
**and** ` eu-central ` profiles are active, the ` server.address ` property is
` 192.168.1.120 ` . If the ` development ` , ` production ` and ` eu-central `
profiles a... | |
spring_io/bootfeaturesexternal_156_0.txt | ![\[Tip\]](images/tip.png) | Tip
---|--- | |
spring_io/springbootproperties_0_0.txt | Enable JavaScript and cookies to continue | |
spring_io/environmentvariables_12_0.txt | Environment variables are OS-specific. Those are stored for global usage. For
example, we install Java in a specific path. The common path is "C:\Program
Files\Java\jdk-17.0.5\bin" in Windows. If we want to do something in the
command line using Java, each time we need to write this path. Instead, we can
store this pat... | |
spring_io/bootfeaturesexternal1_187_0.txt | Property Source | Simple | List
---|---|--- | |
spring_io/bootfeaturesexternal1_16_0.txt | $ java -Dspring.application.json='{"name":"test"}' -jar myapp.jar | |
spring_io/environmentvariables_14_0.txt | * Store database URL and credentials | |
spring_io/spring_io_10_2.txt | ur code
](using.html#using.structuring-your-code) in a sensible way, your main
configuration is usually found.
__ | If you use a test annotation to test a more specific slice of your application , you should avoid adding configuration settings that are specific to a particular area on the main method’s application... | |
spring_io/spring_io_10_14.txt | it. There are ` GraphQlTester `
variants and Spring Boot will auto-configure them depending on the type of
tests:
* the ` ExecutionGraphQlServiceTester ` performs tests on the server side, without a client nor a transport
* the ` HttpGraphQlTester ` performs tests with a client that connects to a server, with or... | |
spring_io/bootfeaturesexternal_142_0.txt | The bean name in the example above will be ` foo-com.example.FooProperties ` . | |
spring_io/bootfeaturesexternal_155_0.txt | _@PostConstruct_
public void openConnection() {
Server server = new Server(this.properties.getRemoteAddress());
// ...
} | |
spring_io/bootfeaturesexternal_19_0.txt | or as a JNDI variable ` java:comp/env/spring.application.json ` . | |
spring_io/bootfeaturesexternal1_107_0.txt | package com.example; | |
spring_io/bootfeaturesexternal_22_0.txt | my.secret=${random.value}
my.number=${random.int}
my.bignumber=${random.long}
my.uuid=${random.uuid}
my.number.less.than.ten=${random.int(10)}
my.number.in.range=${random.int[1024,65536]} | |
spring_io/bootfeaturesexternal_70_0.txt | my:
servers:
- dev.bar.com
- foo.bar.com | |
spring_io/bootfeaturesexternal1_122_0.txt | private List<String> roles = new ArrayList<>(Collections.singleton("USER")); | |
spring_io/environmentvariables_0_0.txt | [ ](/) | |
spring_io/spring_io_10_0.txt | ## 9\. Testing
Spring Boot provides a number of utilities and annotations to help when
testing your application. Test support is provided by two modules: ` spring-
boot-test ` contains core items, and ` spring-boot-test-autoconfigure `
supports auto-configuration for tests.
Most developers use the ` spring-boot-star... | |
spring_io/bootfeaturesexternal_195_0.txt | public static class Security { | |
spring_io/bootfeaturesexternal1_82_0.txt | public List<String> getServers() {
return this.servers;
}
} | |
spring_io/bootfeaturesexternal1_33_0.txt | If you do not like ` application.properties ` as the configuration file name,
you can switch to another file name by specifying a ` spring.config.name `
environment property. You can also refer to an explicit location by using the
` spring.config.location ` environment property (which is a comma-separated
list of direc... | |
spring_io/bootfeaturesexternal1_36_0.txt | $ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties | |
spring_io/bootfeaturesexternal_93_0.txt | ### 24.6.5 Merging YAML lists | |
spring_io/bootfeaturesexternal1_229_0.txt | In the preceding example, if the ` dev ` profile is active, `
AcmeProperties.list ` contains _one_ ` MyPojo ` entry (with a name of ` my
another name ` and a description of ` null ` ). For YAML, both comma-separated
lists and YAML lists can be used for completely overriding the contents of the
list. | |
spring_io/bootfeaturesexternal_188_0.txt | _@NotNull_
private InetAddress remoteAddress; | |
spring_io/bootfeaturesexternal1_192_0.txt | Camel case, kebab case, or underscore notation | |
spring_io/bootfeaturesexternal1_146_0.txt | The preceding configuration creates a regular bean for ` AcmeProperties ` . We
recommend that ` @ConfigurationProperties ` only deal with the environment
and, in particular, does not inject other beans from the context. Keep in mind
that the ` @EnableConfigurationProperties ` annotation is _also_
automatically applied... | |
spring_io/bootfeaturesexternal1_95_0.txt | Spring profiles designated by using the ` spring.profiles ` element may
optionally be negated by using the ` ! ` character. If both negated and non-
negated profiles are specified for a single document, at least one non-negated
profile must match, and no negated profiles may match. | |
spring_io/bootfeaturesexternal1_262_0.txt | * A regular ` long ` representation (using bytes as the default unit unless a ` @DataSizeUnit ` has been specified)
* A more readable format where the value and the unit are coupled (e.g. ` 10MB ` means 10 megabytes) | |
spring_io/bootfeaturesexternal_56_0.txt | app.name=MyApp
app.description=${app.name} is a Spring Boot application | |
spring_io/bootfeaturesexternal1_129_0.txt | }
} | |
spring_io/bootfeaturesexternal1_246_0.txt | Consider the following example: | |
spring_io/environmentvariables_2_0.txt | Follow | |
spring_io/bootfeaturesexternal1_207_0.txt | For YAML files, the brackets need to be surrounded by quotes for the keys to
be parsed properly. | |
spring_io/bootfeaturesexternal_171_0.txt | **Table 24.1. relaxed binding** | |
spring_io/bootfeaturesexternal1_275_0.txt | ![\[Tip\]](images/tip.png) | Tip
---|--- | |
spring_io/bootfeaturesexternal_75_0.txt | private List<String> servers = new ArrayList<String>(); | |
spring_io/bootfeaturesexternal1_108_0.txt | import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; | |
spring_io/bootfeaturesexternal_153_0.txt | _@Autowired_
public MyService(FooProperties properties) {
this.properties = properties;
} | |
spring_io/environmentvariables_20_0.txt | public class Main {
public static void main(String[] args) {
Map<String, String> list = System.getenv(); | |
spring_io/bootfeaturesexternal_60_0.txt | [ YAML ](http://yaml.org) is a superset of JSON, and as such is a very
convenient format for specifying hierarchical configuration data. The `
SpringApplication ` class will automatically support YAML as an alternative to
properties whenever you have the [ SnakeYAML ](http://www.snakeyaml.org/)
library on your classpat... | |
spring_io/bootfeaturesexternal1_47_0.txt | ![\[Note\]](images/note.png) | Note
---|--- | |
spring_io/bootfeaturesexternal1_161_0.txt | ### 25.8.1 Third-party Configuration | |
spring_io/spring_io_10_31.txt | iner<>("neo4j:5");
@Test
void myTest() {
// ...
}
}
Kotlin
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
import org.testcontainers.containers.Neo4jContainer
import org.testcontainers.junit.... | |
spring_io/spring_io_10_36.txt | teBuilderConfiguration {
@Bean
fun restTemplateBuilder(): RestTemplateBuilder {
return RestTemplateBuilder().setConnectTimeout(Duration.ofSeconds(1))
.setReadTimeout(Duration.ofSeconds(1))
}
}
}
| |
spring_io/spring_io_3_10.txt | ..
public boolean isEnabled() {
return this.enabled;
}
public InetAddress getRemoteAddress() {
return this.remoteAddress;
}
public Security getSecurity() {
return this.security;
}
public static class Security... | |
spring_io/bootfeaturesexternal_43_0.txt | This search ordering allows you to specify default values in one configuration
file and then selectively override those values in another. You can provide
default values for you application in ` application.properties ` (or whatever
other basename you choose with ` spring.config.name ` ) in one of the default
locations... | |
spring_io/bootfeaturesexternal1_208_0.txt | #### Binding from Environment Variables | |
spring_io/bootfeaturesexternal_38_0.txt | If ` spring.config.location ` contains directories (as opposed to files) they
should end in ` / ` (and will be appended with the names generated from `
spring.config.name ` before being loaded, including profile-specific file
names). Files specified in ` spring.config.location ` are used as-is, with no
support for prof... | |
spring_io/environmentvariables_27_0.txt |
### Using properties files | |
spring_io/spring_io_5_6.txt | lication.properties ` file
in your Log4j2 configuration.
The following example shows how to set a Log4j2 property named `
applicationName ` that reads ` spring.application.name ` from the Spring `
Environment ` :
<Properties>
<Property name="applicationName">${spring:spring.application.name}</Pr... | |
spring_io/bootfeaturesexternal1_51_0.txt | ## 25.4 Profile-specific Properties | |
spring_io/bootfeaturesexternal_130_0.txt | The POJO above defines the following properties: | |
spring_io/bootfeaturesexternal1_91_0.txt | If none are explicitly active when the application context starts, the default
profiles are activated. So, in the following YAML, we set a value for `
spring.security.user.password ` that is available **only** in the "default"
profile: | |
spring_io/bootfeaturesexternal1_283_0.txt | You can also trigger validation by annotating the ` @Bean ` method that
creates the configuration properties with ` @Validated ` . | |
spring_io/bootfeaturesexternal_121_0.txt | private String password; | |
spring_io/bootfeaturesexternal_162_0.txt | Any property defined with the ` bar ` prefix will be mapped onto that `
BarComponent ` bean in a similar manner as the ` FooProperties ` example
above. | |
spring_io/bootfeaturesexternal1_52_0.txt | In addition to ` application.properties ` files, profile-specific properties
can also be defined by using the following naming convention: `
application-{profile}.properties ` . The ` Environment ` has a set of default
profiles (by default, ` [default] ` ) that are used if no active profiles are
set. In other words, if... | |
spring_io/bootfeaturesexternal1_252_0.txt | public Duration getReadTimeout() {
return this.readTimeout;
} | |
spring_io/bootfeaturesexternal1_11_0.txt | On your application classpath (for example, inside your jar) you can have an `
application.properties ` file that provides a sensible default property value
for ` name ` . When running in a new environment, an ` application.properties
` file can be provided outside of your jar that overrides the ` name ` . For
one-off ... | |
spring_io/spring_io_3_7.txt | ies
It is sometimes useful to only activate a given set of properties when certain
conditions are met. For example, you might have properties that are only
relevant when a specific profile is active.
You can conditionally activate a properties document using `
spring.config.activate.* ` .
The following activation pr... | |
spring_io/bootfeaturesexternal1_181_0.txt | Underscore notation, which is an alternative format for use in ` .properties `
and ` .yml ` files. | |
spring_io/bootfeaturesexternal1_287_0.txt | _@Valid_
private final Security security = new Security(); | |
spring_io/bootfeaturesexternal_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_97_0.txt | YAML files cannot be loaded by using 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_22_0.txt | my.secret=${random.value}
my.number=${random.int}
my.bignumber=${random.long}
my.uuid=${random.uuid}
my.number.less.than.ten=${random.int(10)}
my.number.in.range=${random.int[1024,65536]} | |
spring_io/spring_io_10_16.txt | asses, and configures Spring Data Couchbase repositories.
Regular ` @Component ` and ` @ConfigurationProperties ` beans are not scanned
when the ` @DataCouchbaseTest ` annotation is used. `
@EnableConfigurationProperties ` can be used to include `
@ConfigurationProperties ` beans. (For more about using Couchbase with S... | |
spring_io/bootfeaturesexternal1_19_0.txt | You can also supply the JSON as a JNDI variable, as follows: `
java:comp/env/spring.application.json ` . | |
spring_io/bootfeaturesexternal1_231_0.txt | _@ConfigurationProperties("acme")_
public class AcmeProperties { | |
spring_io/bootfeaturesexternal1_41_0.txt | 1. ` file:./config/ `
2. ` file:./ `
3. ` classpath:/config/ `
4. ` classpath:/ ` | |
spring_io/bootfeaturesexternal1_198_0.txt | Camel case, kebab case, or underscore notation | |
spring_io/bootfeaturesexternal1_203_0.txt | When binding to ` Map ` properties, if the ` key ` contains anything other
than lowercase alpha-numeric characters or ` - ` , you need to use the bracket
notation so that the original value is preserved. If the key is not surrounded
by ` [] ` , any characters that are not alpha-numeric or ` - ` are removed.
For example... | |
spring_io/bootfeaturesexternal_21_0.txt | The ` RandomValuePropertySource ` is useful for injecting random values (e.g.
into secrets or test cases). It can produce integers, longs, uuids or strings,
e.g. | |
spring_io/bootfeaturesexternal_94_0.txt | As [ we have seen above ](boot-features-external-config.html#boot-features-
external-config-loading-yaml "24.6.1 Loading YAML") , any YAML content is
ultimately transformed to properties. That process may be counter intuitive
when overriding “list” properties via a profile. | |
spring_io/bootfeaturesexternal_213_0.txt | [ Prev ](boot-features-spring-application.html) | [ Up ](boot-features.html)
| [ Next ](boot-features-profiles.html)
---|---|---
23\. SpringApplication | [ Home ](index.html) | 25\. Profiles | |
spring_io/spring_io_16_0.txt | ## 15\. What to Read Next
If you want to learn more about any of the classes discussed in this section,
see the [ Spring Boot API documentation ](https://docs.spring.io/spring-
boot/docs/3.2.4/api/) or you can browse the [ source code directly
](https://github.com/spring-projects/spring-boot/tree/v3.2.4) . If you hav... | |
spring_io/environmentvariables_38_0.txt | @Test
public void test() {
Assertions.assertEquals("C:\\Program Files\\Java\\jdk-17.0.5", environment.getProperty("JAVA_HOME"));
}
} | |
spring_io/bootfeaturesexternal_167_0.txt | private String firstName; | |
spring_io/spring_io_2_3.txt | gApplicationBuilder()
.sources(Parent::class.java)
.child(Application::class.java)
.bannerMode(Banner.Mode.OFF)
.run(*args)
__ | There are some restrictions when creating an ` ApplicationContext ` hierarchy. For example, Web components **must** be contained within the child contex... | |
spring_io/bootfeaturesexternal_209_0.txt | Yes | |
spring_io/bootfeaturesexternal_139_0.txt | _@Configuration_
_@EnableConfigurationProperties(FooProperties.class)_
public class MyConfiguration {
} | |
spring_io/bootfeaturesexternal_146_0.txt | This style of configuration works particularly well with the `
SpringApplication ` external YAML configuration: | |
spring_io/bootfeaturesexternal_64_0.txt | Spring Framework provides two convenient classes that can be used to load YAML
documents. The ` YamlPropertiesFactoryBean ` will load YAML as ` Properties `
and the ` YamlMapFactoryBean ` will load YAML as a ` Map ` . | |
spring_io/bootfeaturesexternal1_12_0.txt | ![\[Tip\]](images/tip.png) | Tip
---|--- | |
spring_io/environmentvariables_34_0.txt | @Test
public void viaPropertiesEnvTest() {
Assertions.assertEquals("C:\\Program Files\\Java\\jdk-17.0.5", bean.getEnvViaProperties());
} | |
spring_io/bootfeaturesexternal_180_0.txt | Upper case format. Recommended when using a system environment variables. | |
spring_io/bootfeaturesexternal1_127_0.txt | public List<String> getRoles() { ... } | |
spring_io/spring_io_10_6.txt | rt org.springframework.test.web.reactive.server.WebTestClient;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class MyRandomPortWebTestClientTests {
@Test
void exampleTest(@Autowired WebTestClient webClient) {
webClient
.get().uri("/")
... | |
spring_io/bootfeaturesexternal1_111_0.txt | private boolean enabled; | |
spring_io/spring_io_13_5.txt | typically useful. In a nutshell, adding the starter should provide everything needed to start using that library.
This separation in two modules is in no way necessary. If "acme" has several
flavors, options or optional features, then it is better to separate the auto-
configuration as you can clearly express the fac... | |
spring_io/bootfeaturesexternal1_83_0.txt | ### 25.7.2 Exposing YAML as Properties in the Spring Environment | |
spring_io/bootfeaturesexternal1_45_0.txt | 1. ` file:./custom-config/ `
2. ` classpath:custom-config/ `
3. ` file:./config/ `
4. ` file:./ `
5. ` classpath:/config/ `
6. ` classpath:/ ` | |
spring_io/environmentvariables_39_0.txt |
Also, we can use the System.getenv() method from standard java.lang package. | |
spring_io/bootfeaturesexternal_164_0.txt | Spring Boot uses some relaxed rules for binding ` Environment ` properties to
` @ConfigurationProperties ` beans, so there doesn’t need to be an exact match
between the ` Environment ` property name and the bean property name. Common
examples where this is useful include dashed separated (e.g. ` context-path `
binds to... | |
spring_io/bootfeaturesexternal1_279_0.txt | _@ConfigurationProperties(prefix="acme")_
_@Validated_
public class AcmeProperties { | |
spring_io/bootfeaturesexternal1_288_0.txt | // ... getters and setters | |
spring_io/bootfeaturesexternal_118_0.txt | public Security getSecurity() { ... } | |
spring_io/bootfeaturesexternal1_154_0.txt | _@Service_
public class MyService { | |
spring_io/bootfeaturesexternal1_68_0.txt | If you use “Starters”, SnakeYAML is automatically provided by ` spring-boot-
starter ` . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.