Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
10f8a2f6
Commit
10f8a2f6
authored
Jun 11, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
9f306339
452281ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
8 deletions
+31
-8
SpringApplicationBuilder.java
...pringframework/boot/builder/SpringApplicationBuilder.java
+16
-8
SpringApplicationBuilderTests.java
...framework/boot/builder/SpringApplicationBuilderTests.java
+15
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java
View file @
10f8a2f6
...
...
@@ -382,20 +382,28 @@ public class SpringApplicationBuilder {
return
properties
(
getMapFromKeyValuePairs
(
defaultProperties
));
}
private
Map
<
String
,
Object
>
getMapFromKeyValuePairs
(
String
[]
arg
s
)
{
private
Map
<
String
,
Object
>
getMapFromKeyValuePairs
(
String
[]
propertie
s
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
for
(
String
pair
:
args
)
{
int
index
=
pair
.
indexOf
(
":"
);
if
(
index
<=
0
)
{
index
=
pair
.
indexOf
(
"="
);
}
String
key
=
pair
.
substring
(
0
,
index
>
0
?
index
:
pair
.
length
());
String
value
=
index
>
0
?
pair
.
substring
(
index
+
1
)
:
""
;
for
(
String
property
:
properties
)
{
int
index
=
lowestIndexOf
(
property
,
":"
,
"="
);
String
key
=
property
.
substring
(
0
,
index
>
0
?
index
:
property
.
length
());
String
value
=
index
>
0
?
property
.
substring
(
index
+
1
)
:
""
;
map
.
put
(
key
,
value
);
}
return
map
;
}
private
int
lowestIndexOf
(
String
property
,
String
...
candidates
)
{
int
index
=
-
1
;
for
(
String
candidate
:
candidates
)
{
int
candidateIndex
=
property
.
indexOf
(
candidate
);
if
(
candidateIndex
>
0
)
{
index
=
(
index
==
-
1
?
candidateIndex
:
Math
.
min
(
index
,
candidateIndex
));
}
}
return
index
;
}
/**
* Default properties for the environment in the form {@code key=value} or
* {@code key:value}.
...
...
spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java
View file @
10f8a2f6
...
...
@@ -30,6 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.support.StaticApplicationContext
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.core.io.ResourceLoader
;
...
...
@@ -93,6 +94,20 @@ public class SpringApplicationBuilderTests {
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"bar"
)).
isEqualTo
(
"foo"
);
}
@Test
public
void
propertiesWithRepeatSeparator
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
()
.
sources
(
ExampleConfig
.
class
).
contextClass
(
StaticApplicationContext
.
class
)
.
properties
(
"one=c:\\logging.file"
,
"two=a:b"
,
"three:c:\\logging.file"
,
"four:a:b"
);
this
.
context
=
application
.
run
();
ConfigurableEnvironment
environment
=
this
.
context
.
getEnvironment
();
assertThat
(
environment
.
getProperty
(
"one"
)).
isEqualTo
(
"c:\\logging.file"
);
assertThat
(
environment
.
getProperty
(
"two"
)).
isEqualTo
(
"a:b"
);
assertThat
(
environment
.
getProperty
(
"three"
)).
isEqualTo
(
"c:\\logging.file"
);
assertThat
(
environment
.
getProperty
(
"four"
)).
isEqualTo
(
"a:b"
);
}
@Test
public
void
specificApplicationContextClass
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment