Por algum motivo ele não esta reconhecendo o meu repository e renderizando este erro no console:
Description:
Field repositorio in br.com.alura.aluraescola.controllers.AlunoController required a bean of type 'br.com.alura.escolalura.repositorys.AlunoRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'br.com.alura.escolalura.repositorys.AlunoRepository' in your configuration.
2020-06-06 17:00:54.960 INFO 13128 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
Após pesquisar inseri esse trecho no SpringBootApplication --> @SpringBootApplication(scanBasePackages= {"com.vz.spring.items"}) e funcionou, porém obtive outro erro ao acessar o http://localhost:8080/aluno/cadastrar : Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>br.com.alura.aluraescola</groupId>
<artifactId>escolalura</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>escolalura</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.5.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
EscolaluraApplication.java:
package br.com.alura.aluraescola;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages= {"com.vz.spring.items"})
public class EscolaluraApplication {
public static void main(String[] args) {
SpringApplication.run(EscolaluraApplication.class, args);
}
}
AlunoController.java:
package br.com.alura.aluraescola.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import br.com.alura.escolalura.models.Aluno;
import br.com.alura.escolalura.repositorys.AlunoRepository;
@Controller
public class AlunoController {
@GetMapping("/aluno/cadastrar")
public String cadastrar(Model model){
Aluno aluno = new Aluno();
model.addAttribute("aluno", aluno);
return "aluno/cadastrar";
}
@Autowired
private AlunoRepository repositorio;
@PostMapping("/aluno/salvar")
public String salvar(@ModelAttribute Aluno aluno){
repositorio.salvar(aluno);
System.out.println(aluno);
return "redirect:/";
}
}