File tree 3 files changed +54
-2
lines changed
spring-boot-samples/spring-boot-sample-profile
main/java/org/springframework/boot/sample/profile/service
test/java/org/springframework/boot/sample/profile
3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change
1
+ hello : Bonjour
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2012-2013 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package org .springframework .boot .sample .profile .service ;
18
+
19
+ import org .springframework .beans .factory .annotation .Value ;
20
+ import org .springframework .context .annotation .Profile ;
21
+ import org .springframework .stereotype .Component ;
22
+
23
+ @ Component
24
+ @ Profile ({ "generic" })
25
+ public class GenericService implements MessageService {
26
+
27
+ @ Value ("${hello:Hello}" )
28
+ private String hello ;
29
+
30
+ @ Value ("${name:World}" )
31
+ private String name ;
32
+
33
+ @ Override
34
+ public String getMessage () {
35
+ return this .hello + " " + this .name ;
36
+ }
37
+
38
+ }
Original file line number Diff line number Diff line change @@ -40,8 +40,7 @@ public void before() {
40
40
public void after () {
41
41
if (this .profiles != null ) {
42
42
System .setProperty ("spring.profiles.active" , this .profiles );
43
- }
44
- else {
43
+ } else {
45
44
System .clearProperty ("spring.profiles.active" );
46
45
}
47
46
}
@@ -61,6 +60,20 @@ public void testGoodbyeProfile() throws Exception {
61
60
assertTrue ("Wrong output: " + output , output .contains ("Goodbye Everyone" ));
62
61
}
63
62
63
+ @ Test
64
+ public void testGenericProfile () throws Exception {
65
+ /*
66
+ * This is a profile that requires a new environment property, and one which is
67
+ * only overridden in the current working directory. That file also only contains
68
+ * partial overrides, and the default application.yml should still supply the
69
+ * "name" property.
70
+ */
71
+ System .setProperty ("spring.profiles.active" , "generic" );
72
+ SampleProfileApplication .main (new String [0 ]);
73
+ String output = this .outputCapture .toString ();
74
+ assertTrue ("Wrong output: " + output , output .contains ("Bonjour Phil" ));
75
+ }
76
+
64
77
@ Test
65
78
public void testGoodbyeProfileFromCommandline () throws Exception {
66
79
SampleProfileApplication
You can’t perform that action at this time.
0 commit comments