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

Documentation's "getting-started" page creates spring-boot application in default package #34827

Closed
Rammerhead opened this issue Mar 31, 2023 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@Rammerhead
Copy link

Rammerhead commented Mar 31, 2023

To be more specific, I'm referring to Section 4.3 in the "Getting Started" page at docs.spring.io (which is currently making use of Spring 3.0.5. I have OpenJDK 17 and I build using Maven 3.9.1 on Linux Mint 20.3).

The code provided puts the class in the default package (as no other package gets created), and this ends up causing problems because of @SpringBootApplication. Ultimately, the application fails to start after executing mvn spring-boot:run.

The solution is to create a package in MyApplication.java. I would also recommend to move the file from src/main/java/MyApplication.java to src/main/java/com/example/myproject/MyApplication.java to be more consistent with the tip provided in "Developing with Spring Boot" documentation's "Structuring Your Code" section.

The changed code would finally look like this:

package com.example.myproject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class MyApplication {

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

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

}
@snicoll
Copy link
Member

snicoll commented Apr 4, 2023

Superseded by #34838

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2023
@snicoll snicoll added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 4, 2023
@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: superseded An issue that has been superseded by another labels Apr 11, 2023
@wilkinsona
Copy link
Member

Duplicate of #34513.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants