Skip to content
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

Code sample in "Developing Your First Spring Boot Application" does not work #34513

Closed
tehnodev opened this issue Mar 8, 2023 · 12 comments
Closed
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@tehnodev
Copy link

tehnodev commented Mar 8, 2023

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)
...
@bclozel bclozel transferred this issue from spring-projects/spring-framework Mar 8, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 8, 2023
@bclozel
Copy link
Member

bclozel commented Mar 8, 2023

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?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Mar 8, 2023
@tehnodev
Copy link
Author

tehnodev commented Mar 8, 2023

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

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 8, 2023
@tehnodev
Copy link
Author

tehnodev commented Mar 8, 2023

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

@petrovskimario
Copy link

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

@wilkinsona
Copy link
Member

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.

@petrovskimario
Copy link

petrovskimario commented Jun 21, 2023

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 ?

@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Jun 21, 2023
@philwebb
Copy link
Member

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

@petrovskimario
Copy link

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

@philwebb philwebb changed the title Code sample in Developing Your First Spring Boot Application does not work Code sample in "Developing Your First Spring Boot Application" does not work Jul 19, 2023
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Jul 19, 2023
@snicoll
Copy link
Member

snicoll commented Aug 4, 2023

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

@wilkinsona
Copy link
Member

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

@wilkinsona wilkinsona added the status: blocked An issue that's blocked on an external project change label Aug 4, 2023
@philwebb philwebb removed the status: blocked An issue that's blocked on an external project change label Nov 8, 2023
@philwebb
Copy link
Member

philwebb commented Nov 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

7 participants