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

After upgrading Spring Boot from 3.1.5 to 3.2.0 properties from application.properties are missing #39940

Closed
anvo1115 opened this issue Mar 13, 2024 · 8 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@anvo1115
Copy link

anvo1115 commented Mar 13, 2024

Please, refer to spring-cloud/spring-cloud-config#2376

Can you check the case:

  1. Take the demo from the Spring Cloud issue

  2. Add to the test class DemoApplicationTests


@SpringBootTest(properties = {
		"spring.config.import=optional:configserver:http://localhost:8065"
			})

Than you will see that the default value for myProperty was returned instead of value from application.properties.

Is it normal? It seems that earlier we didn't have this issue.

@philwebb
Copy link
Member

@anvo1115 Can you please provide the config server application that works with the demo. I currently get "Connection refused".

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Mar 14, 2024
@anvo1115
Copy link
Author

@philwebb , you don't need config-server application to run the test. To reproduce you just need to run DemoApplicationTests -> contextLoads test.

image

@anvo1115
Copy link
Author

image

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 19, 2024
@wilkinsona
Copy link
Member

wilkinsona commented Mar 19, 2024

That doesn't work for me, with or without adding the properties attribute to @SpringBootTest on DemoApplicationTests. I can only get the test to run by also removing the spring.config.import entry from application.properties. It then produces the following output:

09:39:42.179 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.demo.DemoApplicationTests]: DemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
09:39:42.249 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.demo.DemoApplication for test class com.example.demo.DemoApplicationTests

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v3.1.9-SNAPSHOT)

2024-03-19T09:39:42.776Z  INFO 32213 --- [           main] com.example.demo.DemoApplicationTests    : Starting DemoApplicationTests using Java 17.0.1 with PID 32213 (started by awilkinson in /Users/awilkinson/Downloads/demo)
2024-03-19T09:39:42.777Z  INFO 32213 --- [           main] com.example.demo.DemoApplicationTests    : No active profile set, falling back to 1 default profile: "default"
2024-03-19T09:39:43.131Z  INFO 32213 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=d9e6cb92-a6b3-3fe6-81fb-6259ea55e64e
2024-03-19T09:39:43.334Z  INFO 32213 --- [           main] com.example.demo.DemoApplicationTests    : Started DemoApplicationTests in 0.959 seconds (process running for 1.584)
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

Note that lack of **** myProperty … output.

The sample's also using 3.1.9-SNAPSHOT but this issue's title says that the problem only occurs with 3.2.

Can you please provide a minimal sample that reproduces the problem without requiring any modifications?

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 19, 2024
@anvo1115
Copy link
Author

anvo1115 commented Mar 25, 2024

I will be able to update Demo after the release of spring-cloud/spring-cloud-config#2376 (comment)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 25, 2024
@scottfrederick scottfrederick added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 25, 2024
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Apr 1, 2024
@anvo1115
Copy link
Author

anvo1115 commented Apr 1, 2024

Please, check the attached demo project. I upgraded spring-cloud and spring-boot.
demo.zip

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Apr 1, 2024
@philwebb
Copy link
Member

philwebb commented Apr 4, 2024

Thanks for the sample @anvo1115.

From a Spring Boot perspective I think this is working as designed. Any spring.config.import value is evaluated with the properties that have been loaded up to that point.

When you have:

@SpringBootTest(properties = {"spring.config.import=optional:configserver:http://localhost:8065"})

Spring Boot will attempt to import from optional:configserver:http://localhost:8065 before it's attempted to load any other properties. This means that my-property hasn't been set because none of the application.properties files have even started to be loaded.

If you remove properties from the @SpringBootTest annotation then things do work because the spring.config.import is initiated from the value in application.properties and by that time my-property is available.

Likewise, if you did the following:

@SpringBootTest(properties = {"spring.config.import=optional:configserver:http://localhost:8065", "my-property=foo"})

You'd also see my-property being resolved.

I'm not sure why things changed when you upgraded dependencies. I don't think we've touched the area of code in Spring Boot that handles imports so I suspect it's something in Spring Cloud.

As a fix, I would suggest updating your application.properties to something like this:

my-property=foo
myserver=http://therealserver.example.com:8065
spring.config.import=optional:configserver:${myserver}

Then in your test do:

@SpringBootTest(properties = { "myserver=http://localhost:8065" })

That way the spring.config.import is initiated when application.properties is loaded which is late enough for my-property to be available.

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2024
@philwebb philwebb added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants