spring-guides/tut-rest

Improvements for beginners

Closed this issue · 6 comments

I am following the same tutorial and came across the same problem with the methods "linkTo" and "methodOn" in the Class EmployeeController.java.

It seems like the import should be from:
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

However, at this point I am not able to guess what to import and the Spring Tools 4 Eclipse IDE is not suggesting anything to import.

By looking up around I found clues in this class: https://github.com/spring-projects/spring-hateoas-examples/blob/master/simplified/src/main/java/org/springframework/hateoas/examples/EmployeeController.java

More over, at the bottom of the tutorial page there is a link to the GitHub repo of complete project:
https://github.com/spring-guides/tut-rest
It would be useful for beginners to have this information at the beginning of the tutorial so I can have a look inside it in situations like this.

I also found problems running the "LoadDatabase.java" when following the tutorial. To fix this, I had to make it implement the CommandLineRunner and put the original code inside it's run method:
I am following the same tutorial and came across the same problem with the methods "linkTo" and "methodOn" in the Class EmployeeController.java.

It seems like the import should be from:
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

However, at this point I am not able to guess what to import and the Spring Tools 4 Eclipse IDE is not suggesting anything to import.

By looking up around I found clues in this class: https://github.com/spring-projects/spring-hateoas-examples/blob/master/simplified/src/main/java/org/springframework/hateoas/examples/EmployeeController.java

More over, at the bottom of the tutorial page there is a link to the GitHub repo of complete project:
https://github.com/spring-guides/tut-rest
It would be useful for beginners to have this information at the beginning of the tutorial so I can have a look inside it in situations like this.

I also found problems running the "LoadDatabase.java" when following the tutorial. To fix this, I had to make it implement the CommandLineRunner and put the original code inside it's run method:

@Component
public class LoadDatabase implements CommandLineRunner {

    private static final Logger log = LoggerFactory.getLogger(LoadDatabase.class);

    @Override
    public void run(String... args) throws Exception {

        employeeRepository.save(new Employee("Bilbo", "Baggins", "burglar"));
        employeeRepository.save(new Employee("Frodo", "Baggins", "thief"));

        employeeRepository.findAll().forEach(employee -> log.info("Preloaded " + employee));

        orderRepository.save(new Order("MacBook Pro", Status.COMPLETED));
        orderRepository.save(new Order("iPhone", Status.IN_PROGRESS));

        orderRepository.findAll().forEach(order -> {
            log.info("Preloaded " + order);
        });
    }

    @Autowired
    EmployeeRepository employeeRepository;
    @Autowired
    OrderRepository orderRepository;
}

I had the same problem with methodOn and linkTo using vs code with the recommended java- and spring-extensions. A quick mention of new imports with each step of the tutorial would've been helpful, I guess.

It looks like it is still open so it has not been solved.

The issue must be with html responsive layout. It positions the link to the tutorial at the bottom of the example on narrow screens.

I had this same issue, when the tutorial switched from showing every package statement, to not telling you that additional import package statements would be required. Is this project open to beginner pull requests to solve this issue? It seems that none of the main contributors have the time to deal with this.

Had the same problem!
Fix: import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
Has the same thoughts as @JulMack, so I opened an issue (Add import to code snippet!).
😎

There is a note "This tutorial is based on Spring MVC and uses the static helper methods from WebMvcLinkBuilder to build these links. If you are using Spring WebFlux in your project, you must instead use WebFluxLinkBuilder." below the code example, but it might be useful to place this before the code so as people are not confused when following the tutorial.

Hi @mlewan01. Thank you for the issue and the details on how to improve the guide. Granted, it is a bit late in the update, but I used feedback in this issue to address some specific problems in PR #127.

It seems like the import should be from:
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

I had trouble finding these imports too. I called out these imports in the README explicitly.

More over, at the bottom of the tutorial page there is a link to the GitHub repo of complete project:
https://github.com/spring-guides/tut-rest
It would be useful for beginners to have this information at the beginning of the tutorial so I can have a look inside it in situations like this.

For any guide on spring.io/guides, you should be able to use the Go To Repo link in the Get the Code section in the top right navigation box. But that's more a note on our common format, and I take your point that the text of this tutorial didn't let the user know soon enough that there is a solution repository out there. I added the completed GitHub repo link two times in the Getting Started header. This is the place that the user decides if they want to start their own project or use the ready made solution. I hope it's more clear now.

By looking up around I found clues in this class...

I found your issue interesting in how you searched for the answers. I think the general navigation of how the solution code repository mapped to the tutorial text was a bit confusing, at least to me. The README builds up a single application, but the solution repository has 4 different modules to help the user jump in and out of specific points in the lesson. I tried to make the mapping from tutorial section to code module more obvious with this paragraph and subsequent links.

I will close the issue as complete, as I believe all concerns were fixed with PR #127. If any concerns from this issue, please add a comment here to open a new issue. Thank you again for your feedback.