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
contractTest task cannot use correct profile file when default profile #1981
Comments
Is this a problem with Contract only? Do you put contract out of the equation does Spring Boot work well with profiles and properties? |
There are also some JDBC tests in the
|
That's really strange, cause we're not building anything on top of these, we're just using Spring Boot annotations. Any ideas @sbrannen what might be going on here? |
I admit: it does sound a bit strange. But it doesn't sound to me like it has anything to do with the core Spring Framework (
It's Spring Boot that is responsible for processing those Even though they're outdated, the following issues seem somewhat related.
If you cannot sort out the cause, I'd suggest contacting the Spring Boot team. |
Thanks! Spring Cloud Contract on the producer side is really just generating the test classes, it's up to the user to setup the base class for the generated test classes. It doesn't impact how you're setting it up so if there are problems with that indeed there can be a problem with Boot. Preferable approach would be to remove Spring Cloud Contract from the equation, create a similar test set up with just Boot (database, a test class, base class that sets up profiles) and see if the problem still persists. |
There might be another clue for the problem -- the folders of generated contract tests code. As in my environment, there are two folders for them -- I'm not sure whether it is the reason that the contract tests loads the |
Summoning @shanman190 😬 🙏 |
So the issue here is the classic classpath order problem. Since the file name is the same in both I'm pretty positive that it's just a matter of flipping the order in the link above which appears to be the order in which Gradle also uses internally by default. |
Will you file a PR or should I look into that? I think we're releasing SCC today so this would go in in the next release |
@marcingrzejszczak, sure I can grab it. What's the current branch baseline that I should target? 3.1.x? |
Describe the bug
The application use Spring boot 3.1.3 and Spring Contract 4.0.4 with gradle (kotlin DSL).
The application has two
application.yml
configuration files, the one of which locates in/src/main/resources
and the other in/src/test/resources
. ABaseTestClass
for contract tests is also under the/src/test/java/...
.
The
application.yml
inmain
folder configurates a JDBC connection to PostgreSQL DB which is used in production environment and the one intest
folder configurates a connetion to in-memory H2 DB which is for testing purpose.When running the
contractTest
task, the exception showsIt seems the test using the configurations in the
main
application.yml file.I tried to add
@ActiveProfiles("test")
annotation forBaseTestsClass
and then just copy and rename thetest
application.yml file totest
application-test.yml file. Then, thecontractTest
task works correctly. Therefore, the problem only occurs fordefault
profile, in where thecontractTest
task loads themain
configuration file but thetest
one.Sample
The application can be found at repo.
The text was updated successfully, but these errors were encountered: