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
bdc949d1
Commit
bdc949d1
authored
Sep 21, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove deprecated merge and locations attributes from @ConfigurationProperties
Closes gh-6972
parent
c108da9d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
7 additions
and
217 deletions
+7
-217
ConfigurationProperties.java
...work/boot/context/properties/ConfigurationProperties.java
+0
-24
ConfigurationPropertiesBindingPostProcessor.java
...operties/ConfigurationPropertiesBindingPostProcessor.java
+4
-52
ConfigurationPropertiesBindingPostProcessorTests.java
...ies/ConfigurationPropertiesBindingPostProcessorTests.java
+0
-55
EnableConfigurationPropertiesTests.java
...ontext/properties/EnableConfigurationPropertiesTests.java
+3
-71
map.yml
spring-boot/src/test/resources/map.yml
+0
-5
name.yml
spring-boot/src/test/resources/name.yml
+0
-10
No files found.
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java
View file @
bdc949d1
...
@@ -87,28 +87,4 @@ public @interface ConfigurationProperties {
...
@@ -87,28 +87,4 @@ public @interface ConfigurationProperties {
*/
*/
boolean
exceptionIfInvalid
()
default
true
;
boolean
exceptionIfInvalid
()
default
true
;
/**
* Optionally provide explicit resource locations to bind to. By default the
* configuration at these specified locations will be merged with the default
* configuration. These resources take precedence over any other property sources
* defined in the environment.
* @return the path (or paths) of resources to bind to
* @see #merge()
* @deprecated as of 1.4 in favor of configuring the environment directly with
* additional locations
*/
@Deprecated
String
[]
locations
()
default
{};
/**
* Flag to indicate that configuration loaded from the specified locations should be
* merged with the default configuration.
* @return the flag value (default true)
* @see #locations()
* @deprecated as of 1.4 along with {@link #locations()} in favor of configuring the
* environment directly with additional locations
*/
@Deprecated
boolean
merge
()
default
true
;
}
}
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java
View file @
bdc949d1
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
context
.
properties
;
package
org
.
springframework
.
boot
.
context
.
properties
;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
...
@@ -36,13 +35,11 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
...
@@ -36,13 +35,11 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.boot.bind.PropertiesConfigurationFactory
;
import
org.springframework.boot.bind.PropertiesConfigurationFactory
;
import
org.springframework.boot.env.PropertySourcesLoader
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.ResourceLoaderAware
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
...
@@ -58,9 +55,6 @@ import org.springframework.core.env.MutablePropertySources;
...
@@ -58,9 +55,6 @@ import org.springframework.core.env.MutablePropertySources;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.PropertySources
;
import
org.springframework.core.env.PropertySources
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
...
@@ -77,10 +71,9 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
...
@@ -77,10 +71,9 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
* @author Christian Dupuis
* @author Christian Dupuis
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
public
class
ConfigurationPropertiesBindingPostProcessor
public
class
ConfigurationPropertiesBindingPostProcessor
implements
BeanPostProcessor
,
implements
BeanPostProcessor
,
BeanFactoryAware
,
ResourceLoaderAware
,
BeanFactoryAware
,
EnvironmentAware
,
ApplicationContextAware
,
InitializingBean
,
EnvironmentAware
,
ApplicationContextAware
,
InitializingBean
,
DisposableBean
,
DisposableBean
,
ApplicationListener
<
ContextRefreshedEvent
>,
PriorityOrdered
{
ApplicationListener
<
ContextRefreshedEvent
>,
PriorityOrdered
{
/**
/**
* The bean name of the configuration properties validator.
* The bean name of the configuration properties validator.
...
@@ -107,8 +100,6 @@ public class ConfigurationPropertiesBindingPostProcessor
...
@@ -107,8 +100,6 @@ public class ConfigurationPropertiesBindingPostProcessor
private
BeanFactory
beanFactory
;
private
BeanFactory
beanFactory
;
private
ResourceLoader
resourceLoader
=
new
DefaultResourceLoader
();
private
Environment
environment
=
new
StandardEnvironment
();
private
Environment
environment
=
new
StandardEnvironment
();
private
ApplicationContext
applicationContext
;
private
ApplicationContext
applicationContext
;
...
@@ -195,11 +186,6 @@ public class ConfigurationPropertiesBindingPostProcessor
...
@@ -195,11 +186,6 @@ public class ConfigurationPropertiesBindingPostProcessor
this
.
beanFactory
=
beanFactory
;
this
.
beanFactory
=
beanFactory
;
}
}
@Override
public
void
setResourceLoader
(
ResourceLoader
resourceLoader
)
{
this
.
resourceLoader
=
resourceLoader
;
}
@Override
@Override
public
void
setEnvironment
(
Environment
environment
)
{
public
void
setEnvironment
(
Environment
environment
)
{
this
.
environment
=
environment
;
this
.
environment
=
environment
;
...
@@ -315,19 +301,12 @@ public class ConfigurationPropertiesBindingPostProcessor
...
@@ -315,19 +301,12 @@ public class ConfigurationPropertiesBindingPostProcessor
return
bean
;
return
bean
;
}
}
@SuppressWarnings
(
"deprecation"
)
private
void
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
,
private
void
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
,
ConfigurationProperties
annotation
)
{
ConfigurationProperties
annotation
)
{
Object
target
=
bean
;
Object
target
=
bean
;
PropertiesConfigurationFactory
<
Object
>
factory
=
new
PropertiesConfigurationFactory
<
Object
>(
PropertiesConfigurationFactory
<
Object
>
factory
=
new
PropertiesConfigurationFactory
<
Object
>(
target
);
target
);
if
(
annotation
!=
null
&&
annotation
.
locations
().
length
!=
0
)
{
factory
.
setPropertySources
(
this
.
propertySources
);
factory
.
setPropertySources
(
loadPropertySources
(
annotation
.
locations
(),
annotation
.
merge
()));
}
else
{
factory
.
setPropertySources
(
this
.
propertySources
);
}
factory
.
setValidator
(
determineValidator
(
bean
));
factory
.
setValidator
(
determineValidator
(
bean
));
// If no explicit conversion service is provided we add one so that (at least)
// If no explicit conversion service is provided we add one so that (at least)
// comma-separated arrays of convertibles can be bound automatically
// comma-separated arrays of convertibles can be bound automatically
...
@@ -398,33 +377,6 @@ public class ConfigurationPropertiesBindingPostProcessor
...
@@ -398,33 +377,6 @@ public class ConfigurationPropertiesBindingPostProcessor
return
true
;
return
true
;
}
}
private
PropertySources
loadPropertySources
(
String
[]
locations
,
boolean
mergeDefaultSources
)
{
try
{
PropertySourcesLoader
loader
=
new
PropertySourcesLoader
();
for
(
String
location
:
locations
)
{
Resource
resource
=
this
.
resourceLoader
.
getResource
(
this
.
environment
.
resolvePlaceholders
(
location
));
String
[]
profiles
=
this
.
environment
.
getActiveProfiles
();
for
(
int
i
=
profiles
.
length
;
i
--
>
0
;)
{
String
profile
=
profiles
[
i
];
loader
.
load
(
resource
,
profile
);
}
loader
.
load
(
resource
);
}
MutablePropertySources
loaded
=
loader
.
getPropertySources
();
if
(
mergeDefaultSources
)
{
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
loaded
.
addLast
(
propertySource
);
}
}
return
loaded
;
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
private
ConversionService
getDefaultConversionService
()
{
private
ConversionService
getDefaultConversionService
()
{
if
(
this
.
defaultConversionService
==
null
)
{
if
(
this
.
defaultConversionService
==
null
)
{
DefaultConversionService
conversionService
=
new
DefaultConversionService
();
DefaultConversionService
conversionService
=
new
DefaultConversionService
();
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java
View file @
bdc949d1
...
@@ -219,29 +219,6 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -219,29 +219,6 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
.
isEqualTo
(
"foo"
);
.
isEqualTo
(
"foo"
);
}
}
@Test
public
void
placeholderResolutionWithCustomLocation
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
"fooValue=bar"
);
this
.
context
.
register
(
CustomConfigurationLocation
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
CustomConfigurationLocation
.
class
).
getFoo
())
.
isEqualTo
(
"bar"
);
}
@Test
public
void
placeholderResolutionWithUnmergedCustomLocation
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
"fooValue:bar"
);
this
.
context
.
register
(
UnmergedCustomConfigurationLocation
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
UnmergedCustomConfigurationLocation
.
class
).
getFoo
())
.
isEqualTo
(
"${fooValue}"
);
}
@Test
@Test
public
void
configurationPropertiesWithFactoryBean
()
throws
Exception
{
public
void
configurationPropertiesWithFactoryBean
()
throws
Exception
{
ConfigurationPropertiesWithFactoryBean
.
factoryBeanInit
=
false
;
ConfigurationPropertiesWithFactoryBean
.
factoryBeanInit
=
false
;
...
@@ -626,38 +603,6 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -626,38 +603,6 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
}
}
@EnableConfigurationProperties
@ConfigurationProperties
(
locations
=
"custom-location.yml"
)
public
static
class
CustomConfigurationLocation
{
private
String
foo
;
public
String
getFoo
()
{
return
this
.
foo
;
}
public
void
setFoo
(
String
foo
)
{
this
.
foo
=
foo
;
}
}
@EnableConfigurationProperties
@ConfigurationProperties
(
locations
=
"custom-location.yml"
,
merge
=
false
)
public
static
class
UnmergedCustomConfigurationLocation
{
private
String
foo
;
public
String
getFoo
()
{
return
this
.
foo
;
}
public
void
setFoo
(
String
foo
)
{
this
.
foo
=
foo
;
}
}
@Configuration
@Configuration
@EnableConfigurationProperties
@EnableConfigurationProperties
public
static
class
ConfigurationPropertiesWithFactoryBean
{
public
static
class
ConfigurationPropertiesWithFactoryBean
{
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java
View file @
bdc949d1
...
@@ -278,61 +278,6 @@ public class EnableConfigurationPropertiesTests {
...
@@ -278,61 +278,6 @@ public class EnableConfigurationPropertiesTests {
assertThat
(
this
.
context
.
getBean
(
TestProperties
.
class
).
name
).
isEqualTo
(
"bar"
);
assertThat
(
this
.
context
.
getBean
(
TestProperties
.
class
).
name
).
isEqualTo
(
"bar"
);
}
}
@Test
public
void
testBindingDirectlyToFile
()
{
this
.
context
.
register
(
ResourceBindingProperties
.
class
,
TestConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeanNamesForType
(
ResourceBindingProperties
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ResourceBindingProperties
.
class
).
name
)
.
isEqualTo
(
"foo"
);
}
@Test
public
void
testBindingDirectlyToFileResolvedFromEnvironment
()
{
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
"binding.location=classpath:other.yml"
);
this
.
context
.
register
(
ResourceBindingProperties
.
class
,
TestConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeanNamesForType
(
ResourceBindingProperties
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ResourceBindingProperties
.
class
).
name
)
.
isEqualTo
(
"other"
);
}
@Test
public
void
testBindingDirectlyToFileWithDefaultsWhenProfileNotFound
()
{
this
.
context
.
register
(
ResourceBindingProperties
.
class
,
TestConfiguration
.
class
);
this
.
context
.
getEnvironment
().
addActiveProfile
(
"nonexistent"
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeanNamesForType
(
ResourceBindingProperties
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ResourceBindingProperties
.
class
).
name
)
.
isEqualTo
(
"foo"
);
}
@Test
public
void
testBindingDirectlyToFileWithExplicitSpringProfile
()
{
this
.
context
.
register
(
ResourceBindingProperties
.
class
,
TestConfiguration
.
class
);
this
.
context
.
getEnvironment
().
addActiveProfile
(
"super"
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeanNamesForType
(
ResourceBindingProperties
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ResourceBindingProperties
.
class
).
name
)
.
isEqualTo
(
"bar"
);
}
@Test
public
void
testBindingDirectlyToFileWithTwoExplicitSpringProfiles
()
{
this
.
context
.
register
(
ResourceBindingProperties
.
class
,
TestConfiguration
.
class
);
this
.
context
.
getEnvironment
().
setActiveProfiles
(
"super"
,
"other"
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeanNamesForType
(
ResourceBindingProperties
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ResourceBindingProperties
.
class
).
name
)
.
isEqualTo
(
"spam"
);
}
@Test
@Test
public
void
testBindingWithTwoBeans
()
{
public
void
testBindingWithTwoBeans
()
{
this
.
context
.
register
(
MoreConfiguration
.
class
,
TestConfiguration
.
class
);
this
.
context
.
register
(
MoreConfiguration
.
class
,
TestConfiguration
.
class
);
...
@@ -415,14 +360,13 @@ public class EnableConfigurationPropertiesTests {
...
@@ -415,14 +360,13 @@ public class EnableConfigurationPropertiesTests {
@Test
@Test
public
void
testBindingWithMapKeyWithPeriod
()
{
public
void
testBindingWithMapKeyWithPeriod
()
{
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
"mymap.key1.key2:value12"
,
"mymap.key3:value3"
);
this
.
context
.
register
(
ResourceBindingPropertiesWithMap
.
class
);
this
.
context
.
register
(
ResourceBindingPropertiesWithMap
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
ResourceBindingPropertiesWithMap
bean
=
this
.
context
ResourceBindingPropertiesWithMap
bean
=
this
.
context
.
getBean
(
ResourceBindingPropertiesWithMap
.
class
);
.
getBean
(
ResourceBindingPropertiesWithMap
.
class
);
assertThat
(
bean
.
mymap
.
get
(
"key3"
)).
isEqualTo
(
"value3"
);
assertThat
(
bean
.
mymap
.
get
(
"key3"
)).
isEqualTo
(
"value3"
);
// this should not fail!!!
// mymap looks to contain - {key1=, key3=value3}
assertThat
(
bean
.
mymap
.
get
(
"key1.key2"
)).
isEqualTo
(
"value12"
);
assertThat
(
bean
.
mymap
.
get
(
"key1.key2"
)).
isEqualTo
(
"value12"
);
}
}
...
@@ -772,20 +716,8 @@ public class EnableConfigurationPropertiesTests {
...
@@ -772,20 +716,8 @@ public class EnableConfigurationPropertiesTests {
}
}
@ConfigurationProperties
(
locations
=
"${binding.location:classpath:name.yml}"
)
protected
static
class
ResourceBindingProperties
{
private
String
name
;
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
// No getter - you should be able to bind to a write-only bean
}
@EnableConfigurationProperties
@EnableConfigurationProperties
@ConfigurationProperties
(
locations
=
"${binding.location:classpath:map.yml}"
)
@ConfigurationProperties
protected
static
class
ResourceBindingPropertiesWithMap
{
protected
static
class
ResourceBindingPropertiesWithMap
{
private
Map
<
String
,
String
>
mymap
;
private
Map
<
String
,
String
>
mymap
;
...
...
spring-boot/src/test/resources/map.yml
deleted
100644 → 0
View file @
c108da9d
mymap
:
?
key1.key2
:
value12
?
key3
:
value3
\ No newline at end of file
spring-boot/src/test/resources/name.yml
deleted
100644 → 0
View file @
c108da9d
---
name
:
foo
---
spring.profiles
:
super
name
:
bar
---
spring.profiles
:
other
name
:
spam
\ No newline at end of file
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