Skip to content

@ConditionalOnProperty does not have the same result in versions 1.5.* and 2.0.* #13449

@hengyunabc

Description

@hengyunabc

@ConditionalOnProperty does not have the same result in versions 1.5.* and 2.0.*

Code

ConditionalOnProperty-demo.zip

application.properties:

test.fooKey=foo
test.bar-key=bar
	@Bean
	@ConditionalOnProperty(name = "test.fooKey")
	public static String fooKeyNoDash() {
		return "@ConditionalOnProperty(name = \"test.fooKey\")";
	}

	@Bean
	@ConditionalOnProperty(name = "test.foo-key")
	public static String fooKeyDash() {
		return "@ConditionalOnProperty(name = \"test.foo-key\")";
	}

	@Bean
	@ConditionalOnProperty(name = "test.barKey")
	public static String barKeyNoDash() {
		return "@ConditionalOnProperty(name = \"test.barKey\")";
	}

	@Bean
	@ConditionalOnProperty(name = "test.bar-key")
	public static String barKeyDash() {
		return "@ConditionalOnProperty(name = \"test.bar-key\")";
	}

Result

spring boot 1.5.13.RELEASE

application.properties: 

test.fooKey=foo
test.bar-key=bar

True  :@ConditionalOnProperty(name = "test.fooKey")
False :@ConditionalOnProperty(name = "test.foo-key")
True  :@ConditionalOnProperty(name = "test.barKey")
True  :@ConditionalOnProperty(name = "test.bar-key")
  • @ConditionalOnProperty(name = "test.barKey") is True, because RelaxedPropertyResolver check all RelaxedNames of test.barKey .

spring boot 2.0.2.RELEASE

application.properties: 

test.fooKey=foo
test.bar-key=bar

True  :@ConditionalOnProperty(name = "test.fooKey")
True  :@ConditionalOnProperty(name = "test.foo-key")
False :@ConditionalOnProperty(name = "test.barKey")
True  :@ConditionalOnProperty(name = "test.bar-key")
  • @ConditionalOnProperty(name = "test.foo-key") is True, because org.springframework.boot.context.properties.source.ConfigurationPropertyName

Metadata

Metadata

Labels

status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions