Hi!
I'm trying to use Spring profiles for two beans with the default profile and two other profiles per bean. I have create a unit test with my expectations regarding the bean which should be returned depending on the activated profile. But the result differs and in case I am removing the @Profile annotation for the "default" profile the behavior is again different. Would you please check what is wrong here?
BR. Thomas example.zip
Comment From: snicoll
@thomasulllrich thanks for the project but I can't open it. The build claims that sources are in src
but they are not. Can you simplify it a bit? We don't need the stuff that works as expected, only the bit that you think should behave differently.
Comment From: thomasulllrich
@snicoll Thanks for your feedback. I have broken it down to the case which I don't understand. Please try again. example.zip
Comment From: snicoll
@thomasulllrich can you please check the project build before? It does not.
Comment From: thomasulllrich
Example.zip @snicoll I added the complete Intellij Idea project. Please try again.
Comment From: snicoll
Please try again.
I don't need the complete IJ project. I need you to take the time (and respect ours) that the sample actually does what it is supposed to do. mvn test
still doesn't work:
[ERROR] Failed to execute goal on project example: Could not resolve dependencies for project example:example:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.sap.db.jdbc:ngdbc:jar:2.14.9 (absent): Could not find artifact com.sap.db.jdbc:ngdbc:jar:2.14.9 in central (https://repo.maven.apache.org/maven2)
It turns out the dependency was not required. If I run the command again, nothing happens:
[INFO] --- surefire:3.1.2:test (default-test) @ example ---
[INFO] Using auto detected provider org.apache.maven.surefire.junit4.JUnit4Provider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Unwraping all the unnecessary, it boils down to registering the same bean, in the same configuration class, one having no metadata, and the other having a default profile. Having several methods for the same bean in the same configuration class brings quite a bit of confusion so we're going to deprecate that, see https://github.com/spring-projects/spring-framework/issues/31073.
Your use of the default profile is also quite strange. Usually, you shouldn't have a bean that's created unconditionally and then another with the default profile.
Comment From: thomasulllrich
@snicoll I have updated the project so that it is possible to run the test with Maven and I removed the unresolvable dependency. The problem I wanted to point out is regarding the usage of the default profile. Hope you can see this now. Example.zip
Comment From: snicoll
Did you see the following?
Unwraping all the unnecessary, it boils down to registering the same bean, in the same configuration class, one having no metadata, and the other having a default profile. Having several methods for the same bean in the same configuration class brings quite a bit of confusion so we're going to deprecate that, see https://github.com/spring-projects/spring-framework/issues/31073.
Comment From: thomasulllrich
Yes. But I wanted to show you something different regarding the implicit and explicit declaration of the default profile. You will see it in the test.