Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore support for binding configuration properties from RandomValuePropertySource #26201

Closed
bxvs888 opened this issue Apr 22, 2021 · 4 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@bxvs888
Copy link

bxvs888 commented Apr 22, 2021

env :
macOS 11
jdk 11.10.5
springboot 2.5.0-RC1

application.yml

server:
  port: ${random.int[9680,9682]}
spring:
  application:
    name:  test

main method class

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

}

build.gradle

plugins {
	id 'org.springframework.boot' version '2.5.0-RC1'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
	id 'idea'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
	maven { url 'https://repo.spring.io/milestone' }
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter'
	implementation "org.springframework.boot:spring-boot-starter-webflux"
	implementation('org.springframework.boot:spring-boot-starter-actuator')
	annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
	useJUnitPlatform()
}

error log

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v2.5.0-RC1)

2021-04-22 11:31:52.048  INFO 45287 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 11.0.10.5 on YUNTAOGAOMBP with PID 45287 (/Users/gaoyuntao/app/pandora-boss/tools/demo/out/production/demo started by gaoyuntao in /Users/gaoyuntao/app/pandora-boss/tools/demo)
2021-04-22 11:31:52.051  INFO 45287 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-04-22 11:31:53.178  WARN 45287 --- [           main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.example.demo.DemoApplication]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration
2021-04-22 11:31:53.194  INFO 45287 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-22 11:31:53.220 ERROR 45287 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.example.demo.DemoApplication]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:610) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser.access$800(ConfigurationClassParser.java:111) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:812) ~[spring-context-5.3.6.jar:5.3.6]
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) ~[na:na]
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:809) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:780) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:193) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:64) ~[spring-boot-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:769) ~[spring-boot-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:337) ~[spring-boot-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1347) ~[spring-boot-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336) ~[spring-boot-2.5.0-RC1.jar:2.5.0-RC1]
	at com.example.demo.DemoApplication.main(DemoApplication.java:10) ~[demo/:na]
Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:226) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:372) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:272) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250) ~[spring-context-5.3.6.jar:5.3.6]
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:600) ~[spring-context-5.3.6.jar:5.3.6]
	... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'random.int[9680,9682]' in value "${random.int[9680,9682]}"
	at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) ~[spring-core-5.3.6.jar:5.3.6]
	at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.3.6.jar:5.3.6]
	at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-5.3.6.jar:5.3.6]
	at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.3.6.jar:5.3.6]
	at org.springframework.core.env.AbstractPropertyResolver.resolveNestedPlaceholders(AbstractPropertyResolver.java:230) ~[spring-core-5.3.6.jar:5.3.6]
	at org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertyResolver.getProperty(ConfigurationPropertySourcesPropertyResolver.java:79) ~[spring-boot-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertyResolver.getProperty(ConfigurationPropertySourcesPropertyResolver.java:65) ~[spring-boot-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:599) ~[spring-core-5.3.6.jar:5.3.6]
	at org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType.getPortProperty(ManagementPortType.java:64) ~[spring-boot-actuator-autoconfigure-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType.get(ManagementPortType.java:58) ~[spring-boot-actuator-autoconfigure-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.actuate.autoconfigure.web.server.OnManagementPortCondition.getMatchOutcome(OnManagementPortCondition.java:49) ~[spring-boot-actuator-autoconfigure-2.5.0-RC1.jar:2.5.0-RC1]
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.5.0-RC1.jar:2.5.0-RC1]
	... 25 common frames omitted


Process finished with exit code 1
@bxvs888 bxvs888 changed the title server.port random.int not work Could not resolve placeholder 'random.int[9680,9682]' in value "${random.int[9680,9682]}" server.port random.int not work Could not resolve placeholder 'random.int[9680,9682]' in value "${random.int[9680,9682]}" spring-boot-2.5.0-RC1 Apr 22, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 22, 2021
@wilkinsona
Copy link
Member

Thanks for trying out the release candidate. This appears to be a regression in 2.5 as the problem does not occur with 2.4.5.

@wilkinsona wilkinsona added type: bug A general bug type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Apr 22, 2021
@wilkinsona wilkinsona added this to the 2.5.0 milestone Apr 22, 2021
@wilkinsona
Copy link
Member

The problem doesn't occur with 2.5.0.M3 either. I believe that 6ad100e is the cause. random.int[9680,9682] is a valid configuration property name so ConfigurationPropertySourcesPropertySource is consulted and this.defaultResolver is not:

private Object findPropertyValue(String key, Class<?> targetValueType) {
ConfigurationPropertySourcesPropertySource attached = getAttached();
if (attached != null) {
ConfigurationPropertyName name = ConfigurationPropertyName.of(key, true);
if (name != null) {
try {
ConfigurationProperty configurationProperty = attached.findConfigurationProperty(name);
return (configurationProperty != null) ? configurationProperty.getValue() : null;
}
catch (Exception ex) {
}
}
}
return this.defaultResolver.getProperty(key, targetValueType, false);
}

ConfigurationPropertySourcesPropertySource doesn't consider the random property source as it's filtered out due to 0588e98.

Could you take a look at this one please, @philwebb?

@philwebb philwebb self-assigned this Apr 23, 2021
@philwebb
Copy link
Member

We could revert 0588e98, but I wonder in this example why server.port=0 is not used? @bxvs888 Why do you use ${random.int[9680,9682]}? What happens if a port is already in use?

@bxvs888
Copy link
Author

bxvs888 commented Apr 24, 2021

@philwebb Because it is used in the intranet, only a given range is opened on the network. Other ports do not allow external access. I don't want to give a fixed port.

@philwebb philwebb changed the title server.port random.int not work Could not resolve placeholder 'random.int[9680,9682]' in value "${random.int[9680,9682]}" spring-boot-2.5.0-RC1 Restore support for binding configuration properties from RandomPropertySource Apr 26, 2021
@philwebb philwebb changed the title Restore support for binding configuration properties from RandomPropertySource Restore support for binding configuration properties from RandomValuePropertySource Apr 26, 2021
philwebb added a commit that referenced this issue Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

4 participants