3
respostas

Erro após baixar o projeto final do curso

Baixei o projeto final do curso, e coloquei logo em seguida o @ComponentScan({"controller"}) na minha classe principal, mas sem sucesso. É apresentado o erro abaixo: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon May 09 16:55:52 BRT 2022 There was an unexpected error (type=Not Found, status=404). No message available

3 respostas

package br.com.alura.mvc.mudi;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication @ComponentScan({"controller"}) public class MudiApplication {

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

}

package br.com.alura.mvc.mudi.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping;

import br.com.alura.mvc.mudi.model.Pedido; import br.com.alura.mvc.mudi.model.StatusPedido; import br.com.alura.mvc.mudi.repository.PedidoRepository;

@Controller @RequestMapping("/home") public class HomeController {

@Autowired
private PedidoRepository repository;

@GetMapping()
public String home(Model model) {
    List<Pedido> pedidos = repository.findAll();
    model.addAttribute("pedidos", pedidos);
    return "home"; 
}

@GetMapping("/{status}")
public String porStatus(@PathVariable("status") String status, Model model) {
    List<Pedido> pedidos = repository.findByStatus(StatusPedido.valueOf(status.toUpperCase()));
    model.addAttribute("pedidos", pedidos);
    model.addAttribute("status", status);
    return "home"; 
}

@ExceptionHandler(IllegalArgumentException.class)
public String onError() {
    return "redirect:/home";
}

}

Oi!

O erro acontece em que situação?

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software