Skip to content

Commit 8b0864a

Browse files
authored
doc: split environments docs into multiple sections (#11724)
1 parent ac5020f commit 8b0864a

File tree

6 files changed

+87
-94
lines changed

6 files changed

+87
-94
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Since Micronaut framework 2.3 a banner is shown when the application starts. It is enabled by default, and it also shows the Micronaut version.
2+
3+
[source,shell,subs="attributes"]
4+
----
5+
$ ./gradlew run
6+
__ __ _ _
7+
| \/ (_) ___ _ __ ___ _ __ __ _ _ _| |_
8+
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
9+
| | | | | (__| | | (_) | | | | (_| | |_| | |_
10+
|_| |_|_|\___|_| \___/|_| |_|\__,_|\__,_|\__|
11+
Micronaut ({version})
12+
13+
17:07:22.997 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 611ms. Server Running: http://localhost:8080
14+
----
15+
16+
To customize the banner with your own ASCII Art (just plain ASCII at this moment), create the file `src/main/resources/micronaut-banner.txt` and it will be used instead.
17+
18+
To disable it, modify your `Application` class:
19+
20+
[source,java]
21+
----
22+
public class Application {
23+
24+
public static void main(String[] args) {
25+
Micronaut.build(args)
26+
.banner(false) // <1>
27+
.start();
28+
}
29+
}
30+
----
31+
<1> Disable the banner

src/main/docs/guide/config/environments.adoc

-93
Original file line numberDiff line numberDiff line change
@@ -17,96 +17,3 @@ $ java -Dmicronaut.environments=foo,bar -jar myapp.jar
1717
The above activates environments called `foo` and `bar`.
1818

1919
It is also possible to enable the detection of the Cloud environment the application is deployed to (this feature is disabled by default since Micronaut framework 4). See the section on <<cloudConfiguration,Cloud Configuration>> for more information.
20-
21-
== Environment Priority
22-
23-
The Micronaut framework loads property sources based on the environments specified, and if the same property key exists in multiple property sources specific to an environment, the environment order determines which value to use.
24-
25-
The Micronaut framework uses the following hierarchy for environment processing (lowest to highest priority):
26-
27-
* Deduced environments
28-
* Environments from the `micronaut.environments` system property
29-
* Environments from the `MICRONAUT_ENVIRONMENTS` environment variable
30-
* Environments specified explicitly through the application context builder
31-
+
32-
NOTE: This also applies to `@MicronautTest(environments = ...)`
33-
+
34-
35-
36-
== Disabling Environment Detection
37-
38-
Automatic detection of environments can be disabled by setting the `micronaut.env.deduction` system property or the `MICRONAUT_ENV_DEDUCTION` environment variable to `false`. This prevents the Micronaut framework from detecting current environments, while still using any environments that are specifically provided as shown above.
39-
40-
.Disabling environment detection via system property
41-
[source,bash]
42-
----
43-
$ java -Dmicronaut.env.deduction=false -jar myapp.jar
44-
----
45-
46-
Alternatively, you can disable environment deduction using the api:context.ApplicationContextBuilder[] `deduceEnvironment` method when setting up your application.
47-
48-
snippet::io.micronaut.docs.context.env.DefaultEnvironmentSpec[tags="disableEnvDeduction",indent=0,title="Using ApplicationContextBuilder to disable environment deduction"]
49-
50-
== Default Environment
51-
52-
The Micronaut framework supports the concept of one or many default environments.
53-
A default environment is one that is only applied if no other environments are explicitly specified or deduced.
54-
Environments can be explicitly specified either through the application context builder `Micronaut.build().environments(...)`, through the `micronaut.environments` system property, or the `MICRONAUT_ENVIRONMENTS` environment variable.
55-
Environments can be deduced to automatically apply the environment appropriate for cloud deployments.
56-
If an environment is found through any of the above means, the default environment will *not* be applied.
57-
58-
To set the default environments, include a public static class that implements api:context.ApplicationContextConfigurer[] and is annotated with api:context.annotation.ContextConfigurer[]:
59-
60-
[source,java]
61-
----
62-
public class Application {
63-
64-
@ContextConfigurer
65-
public static class DefaultEnvironmentConfigurer implements ApplicationContextConfigurer {
66-
@Override
67-
public void configure(@NonNull ApplicationContextBuilder builder) {
68-
builder.defaultEnvironments(defaultEnvironment);
69-
}
70-
}
71-
72-
public static void main(String[] args) {
73-
Micronaut.run(Application.class, args);
74-
}
75-
}
76-
----
77-
78-
NOTE: Previously, we recommended using `Micronaut.defaultEnvironments("dev")` however this does not allow the Ahead of Time (AOT) compiler to detect the default environments.
79-
80-
== Micronaut Banner
81-
82-
Since Micronaut framework 2.3 a banner is shown when the application starts. It is enabled by default, and it also shows the Micronaut version.
83-
84-
[source,shell,subs="attributes"]
85-
----
86-
$ ./gradlew run
87-
__ __ _ _
88-
| \/ (_) ___ _ __ ___ _ __ __ _ _ _| |_
89-
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
90-
| | | | | (__| | | (_) | | | | (_| | |_| | |_
91-
|_| |_|_|\___|_| \___/|_| |_|\__,_|\__,_|\__|
92-
Micronaut ({version})
93-
94-
17:07:22.997 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 611ms. Server Running: http://localhost:8080
95-
----
96-
97-
To customize the banner with your own ASCII Art (just plain ASCII at this moment), create the file `src/main/resources/micronaut-banner.txt` and it will be used instead.
98-
99-
To disable it, modify your `Application` class:
100-
101-
[source,java]
102-
----
103-
public class Application {
104-
105-
public static void main(String[] args) {
106-
Micronaut.build(args)
107-
.banner(false) // <1>
108-
.start();
109-
}
110-
}
111-
----
112-
<1> Disable the banner
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
The Micronaut framework supports the concept of one or many default environments.
2+
A default environment is one that is only applied if no other environments are explicitly specified or deduced.
3+
Environments can be explicitly specified either through the application context builder `Micronaut.build().environments(...)`, through the `micronaut.environments` system property, or the `MICRONAUT_ENVIRONMENTS` environment variable.
4+
Environments can be deduced to automatically apply the environment appropriate for cloud deployments.
5+
If an environment is found through any of the above means, the default environment will *not* be applied.
6+
7+
To set the default environments, include a public static class that implements api:context.ApplicationContextConfigurer[] and is annotated with api:context.annotation.ContextConfigurer[]:
8+
9+
[source,java]
10+
----
11+
public class Application {
12+
13+
@ContextConfigurer
14+
public static class DefaultEnvironmentConfigurer implements ApplicationContextConfigurer {
15+
@Override
16+
public void configure(@NonNull ApplicationContextBuilder builder) {
17+
builder.defaultEnvironments(defaultEnvironment);
18+
}
19+
}
20+
21+
public static void main(String[] args) {
22+
Micronaut.run(Application.class, args);
23+
}
24+
}
25+
----
26+
27+
NOTE: Previously, we recommended using `Micronaut.defaultEnvironments("dev")` however this does not allow the Ahead of Time (AOT) compiler to detect the default environments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Automatic detection of environments can be disabled by setting the `micronaut.env.deduction` system property or the `MICRONAUT_ENV_DEDUCTION` environment variable to `false`. This prevents the Micronaut framework from detecting current environments, while still using any environments that are specifically provided as shown above.
2+
3+
.Disabling environment detection via system property
4+
[source,bash]
5+
----
6+
$ java -Dmicronaut.env.deduction=false -jar myapp.jar
7+
----
8+
9+
Alternatively, you can disable environment deduction using the api:context.ApplicationContextBuilder[] `deduceEnvironment` method when setting up your application.
10+
11+
snippet::io.micronaut.docs.context.env.DefaultEnvironmentSpec[tags="disableEnvDeduction",indent=0,title="Using ApplicationContextBuilder to disable environment deduction"]
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The Micronaut framework loads property sources based on the environments specified, and if the same property key exists in multiple property sources specific to an environment, the environment order determines which value to use.
2+
3+
The Micronaut framework uses the following hierarchy for environment processing (lowest to highest priority):
4+
5+
* Deduced environments
6+
* Environments from the `micronaut.environments` system property
7+
* Environments from the `MICRONAUT_ENVIRONMENTS` environment variable
8+
* Environments specified explicitly through the application context builder
9+
+
10+
NOTE: This also applies to `@MicronautTest(environments = ...)`
11+
+

src/main/docs/guide/toc.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ ioc:
6767
android: Android Support
6868
config:
6969
title: Application Configuration
70-
environments: The Environment
70+
environments:
71+
title: The Environment
72+
environmentPriority: Environment Priority
73+
disablingEnvironmentDetection: Disabling Environment Detection
74+
defaultEnvironment: Default Environment
75+
banner: Micronaut Banner
7176
propertySource: Externalized Configuration with PropertySources
7277
valueAnnotation: Configuration Injection
7378
evaluatedExpressions: Expression Language

0 commit comments

Comments
 (0)