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

application-test.properties ignored after upgrading to Spring Boot 2.6.0 (maybe 2.5.7) #28853

Closed
JeromeSimmonds opened this issue Nov 30, 2021 · 10 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@JeromeSimmonds
Copy link

Hi, the following used to work with Spring Boot 2.5.6 (accessing the properties from src/test/resources/application-test.properties)

@SpringBootTest
@ActiveProfiles("test")
@AutoConfigureMockMvc
class SomeClassIT {

    @Autowired
    private MockMvc mockMvc;

    @Value("${info.app.name}")
    private String appName;

    @Test
    public void testEndpointInfo() throws Exception {
        mockMvc.perform(get("/info")).andDo(print())
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.build.name").value(appName))
    }
}

but ignores the test properties file after upgrading to 2.6.0: the value for appName is the one from the default application.properties.
What do we need to change to make the properties from src/test/resources/application-test.properties override the default ones, as it used to do?

PS: I have been told this problem appeared with SB 2.5.7 but I haven't tested.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 30, 2021
@wilkinsona
Copy link
Member

@JeromeSimmonds As @mbhave requested, can you please share a small sample that we can run that reproduces the problem? You can share it with us by zipping it up and attaching it this issue or by pushing it to a separate repository on GitHub.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Nov 30, 2021
@JeromeSimmonds
Copy link
Author

JeromeSimmonds commented Nov 30, 2021

It's going to take me some time to extract the minimum code required from my project to be able to share here (the code I already shared could be added to any Spring Boot project though...), in the meantime can you folks confirm that using those annotations

@SpringBootTest
@ActiveProfiles("test")

still overrides the application.properties values with the ones in src/test/resources/application-test.properties with the Spring Boot app automatically started for the test?
This line that is now failing
.andExpect(jsonPath("$.build.name").value(appName))
indicates that the Spring Boot app gets its properties from application.properties hence the test failure.

@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 Nov 30, 2021
@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 Nov 30, 2021
@antti-markus-cko
Copy link

Not able to reproduce with Spring Boot 2.6.1 https://github.com/antti-markus-cko/issuedemo

@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 Dec 6, 2021
@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 6, 2021
@JeromeSimmonds
Copy link
Author

JeromeSimmonds commented Dec 7, 2021

@antti-markus-cko have you tested with the application-test.properties file in the src/test/resources folder, as I do (and where config files should normally be for tests)?

@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 Dec 7, 2021
@JeromeSimmonds
Copy link
Author

@antti-markus-cko so I tested your project after moving the file to the test folder and it still works.
Now I think the problems comes from the way Actuator gets the values to generate the /info response payload...
Maybe it doesn't use info.app.name anymore...

@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 Dec 7, 2021
@wilkinsona
Copy link
Member

This sort of thing is why we really need a minimal example that reproduces the problem. Unfortunately, we can't investigate a problem that is vague.

@Jeff-Steele
Copy link

My team is experiencing this same issue, we upgraded from Spring Boot 2.4.6 to Spring Boot 2.4.13. The problem is not 100% guaranteed to happen. Sometimes it will load the application-test.yml file and other times it will apparently ignore it. We are using maven, when I clean the project and let IntelliJ build my integration test project that has the application-test.yml and the tests that utilize it, it appears to be happy, however, when I maven install then it appears to ignore the file. At least, that is what I noticed this morning.

@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 Dec 8, 2021
@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 Dec 8, 2021
@Jeff-Steele
Copy link

Additional update, we are copying resources from a different location into our integration tests.

${basedir}/../resources/src/main/resource

So this may have broken for us a while ago and we just didn't notice until more recently. However, adding another testResoruce for the current projects resources places the file in place so it can be loaded. Not sure if this is the same problem the original poster is having as well.

@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 Dec 8, 2021
@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 8, 2021
@JeromeSimmonds
Copy link
Author

@antti-markus-cko @wilkinsona latest update: so the Actuator /info endpoint that I test in the snippet of code I shared, used to return the value of info.app.name defined in properties files. A recent version of Actuator changed the format of the response and now returns a build.name field which I thought would still use the info.app.name var, but it's not the case if I understand https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.info.auto-configured-info-contributors correctly (I use Maven and it gets the value from the pom file apparently).

I understand the problem now, thank you for trying to help!

@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 Dec 8, 2021
@wilkinsona
Copy link
Member

@JeromeSimmonds Correct, the info contributor that exposes every property in the environment that begins with info. is disabled by default in Spring Boot 2.6. Thanks for letting us know you'd figured out the problem.

@wilkinsona wilkinsona 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 Dec 8, 2021
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

8 participants