Skip to content

Exception when using extension #1420

Closed
Closed

Description

@HDwares

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.

Activity

  1. jdneo commented on May 18, 2022

    @jdneo
    Member

    Could you share a sample project which can repro this issue?

  2. HDwares commented on May 18, 2022

    @HDwares
    Author

    Attached is a sample project. Execute the below test classes, you will receive same type of exception "Unable to create Application context, BeanCreationException:

    1. src\test\java\com\example\SpringBootExamples\apiTests\ProductApiTestDummy.java
    2. src\test\java\com\example\SpringBootExamples\unitTests\ProductControllerUnitTest.java

    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

  3. jdneo commented on May 19, 2022

    @jdneo
    Member

    Thank you. I will take a look

  4. HDwares commented on May 19, 2022

    @HDwares
    Author

    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

  5. jdneo commented on May 20, 2022

    @jdneo
    Member

    It's working on my side:

    image

    image

    Do you have any customized settings in your VS Code? Or any environment related settings?

  6. HDwares commented on May 20, 2022

    @HDwares
    Author

    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:
    image

    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.

  7. HDwares commented on May 20, 2022

    @HDwares
    Author

    Attaching the full debug console log for better insight.
    debugConsole.txt

  8. jdneo commented on May 20, 2022

    @jdneo
    Member

    So far have no idea on this. I tried several times but could not repro the issue. 🤔

  9. HDwares commented on May 20, 2022

    @HDwares
    Author

    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.

  10. HDwares commented on May 20, 2022

    @HDwares
    Author

    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.

  11. jdneo commented on May 20, 2022

    @jdneo
    Member

    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.

  12. HDwares commented on May 20, 2022

    @HDwares
    Author

    Can you try after installing spring boot extension pack?

    ext install Pivotal.vscode-boot-dev-pack

  13. HDwares commented on May 20, 2022

    @HDwares
    Author

    I added this setting in workspace settings.json and it solved the problem:

    {
       "boot-java.live-information.automatic-connection.on": false
    }
    

    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.

    image

    Now, you can close the issue if you want.

  14. jdneo commented on May 21, 2022

    @jdneo
    Member

    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??

  15. HDwares commented on May 21, 2022

    @HDwares
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions