You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Receiving BeanCreationException when running spring boot test using Test Runner for Java - VS Code extension. It was working fine till yesterday.
It is still working fine using eclipse' junit runner and also using maven test command.
Error description from debug console:
GenericWebApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springApplicationAdmjnRegistrar' defined in class path resource
SpringApplicationAdminJmxAutoConfiguration.class: Invocation of init method failed; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication.
Please look into this issue, because this extension is very good only because of this issue I will again have to switch to other IDE for Java.
Attached is a sample project. Execute the below test classes, you will receive same type of exception "Unable to create Application context, BeanCreationException:
No, the only workspace vscode setting.json and launch.json which were autogenerated and which I provided in the zip. But I also tried removing them and also removed the user's setting.json, still receiving the same error:
I in fact tried by using different machine as well so as to understand if there is some cache issue, but nope, same result. Strange thing is that 2nd test has started working now in vs code. Not able to understand where is the problem with first test.
If you could tell where can I see the arguments with which the test is running, it would be very helpful. Because I found that on disabling the startSpringBootApplication line and starting application separately test runs fine.
Somehow on executing test using extension application context is being created on it's own, thus it is conflicting with the context created during startSpringBootApplication which is not the case in other IDEs.
Latest update: when I disabled the actuator dependency in pom.xml and also disabled the actuator related classes, all the tests passed.
So, the extension is generating some config when actuator is enabled, due to which it tried to create it's own context before starting the application thus the exception.
So, the extension is generating some config when actuator is enabled, due to which it tried to create it's own context before starting the application thus the exception.
I don't think so. I didn't disable that dependency and the test passes. At least the test runner extension won't do anything related with actuator.
I think this is a feature and not a bug though I didn't find any documentation for that setting on their extension page. Also I don't know what exactly the feature is, how 'true' value in that setting will help a user.
Activity
jdneo commentedon May 18, 2022
Could you share a sample project which can repro this issue?
HDwares commentedon May 18, 2022
Attached is a sample project. Execute the below test classes, you will receive same type of exception "Unable to create Application context, BeanCreationException:
1st one was working fine earlier, 2nd one didn't work ever. After I tried the 2nd I started receiving error for both.
SpringBootExamples.zip
jdneo commentedon May 19, 2022
Thank you. I will take a look
HDwares commentedon May 19, 2022
Fixed the 2nd test as well, now both tests run fine in eclipse, netbeans and intellij but are not working in vs code.
SpringBootExamples.zip
jdneo commentedon May 20, 2022
It's working on my side:
Do you have any customized settings in your VS Code? Or any environment related settings?
HDwares commentedon May 20, 2022
No, the only workspace vscode setting.json and launch.json which were autogenerated and which I provided in the zip. But I also tried removing them and also removed the user's setting.json, still receiving the same error:

I in fact tried by using different machine as well so as to understand if there is some cache issue, but nope, same result. Strange thing is that 2nd test has started working now in vs code. Not able to understand where is the problem with first test.
HDwares commentedon May 20, 2022
Attaching the full debug console log for better insight.
debugConsole.txt
jdneo commentedon May 20, 2022
So far have no idea on this. I tried several times but could not repro the issue. 🤔
HDwares commentedon May 20, 2022
If you could tell where can I see the arguments with which the test is running, it would be very helpful. Because I found that on disabling the startSpringBootApplication line and starting application separately test runs fine.
Somehow on executing test using extension application context is being created on it's own, thus it is conflicting with the context created during startSpringBootApplication which is not the case in other IDEs.
HDwares commentedon May 20, 2022
Latest update: when I disabled the actuator dependency in pom.xml and also disabled the actuator related classes, all the tests passed.
So, the extension is generating some config when actuator is enabled, due to which it tried to create it's own context before starting the application thus the exception.
jdneo commentedon May 20, 2022
I don't think so. I didn't disable that dependency and the test passes. At least the test runner extension won't do anything related with actuator.
HDwares commentedon May 20, 2022
Can you try after installing spring boot extension pack?
ext install Pivotal.vscode-boot-dev-pack
HDwares commentedon May 20, 2022
I added this setting in workspace settings.json and it solved the problem:
It is by default true in default settings.json.
This setting is coming from Spring Boot Tools extension and it has something to do with actuator.
Now, you can close the issue if you want.
jdneo commentedon May 21, 2022
Thank you HDwares for the update.
BTW, do you think that's a bug of the Spring Boot Tools extension, or it's as expected??
HDwares commentedon May 21, 2022
I think this is a feature and not a bug though I didn't find any documentation for that setting on their extension page. Also I don't know what exactly the feature is, how 'true' value in that setting will help a user.