MyApplication.java example code do not work without package declaration. spring-boot:run command shows

...
** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
...
Caused by: java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations$PoolConfiguration due to io/r2dbc/spi/ValidationDepth not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
...

Comment From: bclozel

In which package is your main application located? The error message seems to indicate that it is using an invalid location.

Can you share a sample application showing the problem?

Comment From: tehnodev

No package. File is located as stated in documentation at src/main/java/MyApplication.java

Application sample is copy-paste from documentation file MyApplication.java

Comment From: tehnodev

I suggest to change file location to src/main/java/example/MyApplication.java and add "package example;" at the top of example file

Comment From: petrovskimario

Has this been picked up by anyone ? If not i can pick this up

Comment From: wilkinsona

Thanks for the offer, @petrovskimario. It's all yours.

The code already has a package but it's deliberately removed by the code chomping in our Asciidoctor backend. It should be possible to use chomp_package_replacement to configure the package for this particular code snippet. Please let us know if you have any questions.

Comment From: petrovskimario

Hello @wilkinsona Thank you for assigning this to me. I have been using Spring for a couple of years,but it is my first time contributing to Spring, so can you elaborate on what are the changes that needs to be done? You have mentioned using chomp_package_replacement, but where can i use this ?

Also one more thing I was able to clone and build the project successfully,however when i try to run the MyApplication class which has the main method inside i am getting the following error : java.lang.IllegalStateException: No Docker Compose file found in directory 'D:\SB\spring-boot-project\spring-boot-docs.'

Why is it looking for a docker compose file ?

Comment From: wilkinsona

You can set a document-wide attribute in attributes.adoc:

:chomp_package_replacement: example

But this will affect every code snippet in the documentation. I thought it should also be possible to set it on a per-snippet basis like this:

include::code:MyApplication[chomp_package_replacement=example]

But it doesn't seem to work. Should it have worked, @philwebb?

With the global attribute in place, the package always appears, even when the snippet isn't expanded:

package example;

@RestController
@SpringBootApplication
public class MyApplication {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

}

I'm not sure if this is what we want. It might be nice for the package to be changed but remain hidden until the code's expanded or copied.

Comment From: philwebb

I'll have to take a look at the backend code. We do have this test but it's not using include::code.

Comment From: petrovskimario

Is it maybe possible to use the chomp_package_replacement with some predicates ? For example i am thinking something like this : :chomp_package_replacement: example where package = something

Comment From: snicoll

@petrovskimario do you still need help for this? Any update for us?

Comment From: wilkinsona

@snicoll as per Phil's comment there's a limitation of the Asciidoctor backend that's blocking progress.

Comment From: philwebb

It turns out the the backend does support but the attribute needs to be above the include line and not part of it.