Bom dia, tentei seguir os passos dados no vídeo, mas ao tentar gravar o aluno é disparado um erro diferente, mais precisamente na linha que instancia o MongoClient:
2023-02-05 07:19:49.395 ERROR 25140 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(I)Lcom/mongodb/connection/ConnectionPoolSettings$Builder;] with root cause
java.lang.NoSuchMethodError: com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(I)Lcom/mongodb/connection/ConnectionPoolSettings$Builder; at com.mongodb.MongoClientOptions.(MongoClientOptions.java:140) ~[mongodb-driver-3.5.0.jar:na] at com.mongodb.MongoClientOptions.(MongoClientOptions.java:54) ~[mongodb-driver-3.5.0.jar:na] at com.mongodb.MongoClientOptions$Builder.build(MongoClientOptions.java:1474) ~[mongodb-driver-3.5.0.jar:na] at com.mongodb.MongoClient.(MongoClient.java:163) ~[mongodb-driver-3.5.0.jar:na] at com.mongodb.MongoClient.(MongoClient.java:124) ~[mongodb-driver-3.5.0.jar:na] at br.com.alura.escolaalura.escolaalura.repository.AlunoRepository.salvar(AlunoRepository.java:14) ~[classes/:na] at br.com.alura.escolaalura.escolaalura.controller.AlunoController.salvar(AlunoController.java:27) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
Código da classe AlunoRepository:
package br.com.alura.escolaalura.escolaalura.repository;
import br.com.alura.escolaalura.escolaalura.model.Aluno; import com.mongodb.MongoClient; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.springframework.stereotype.Repository;
@Repository public class AlunoRepository {
public void salvar(Aluno aluno) {
MongoClient mongoClient = new MongoClient();
MongoDatabase escola = mongoClient.getDatabase("escola");
MongoCollection<Aluno> alunos = escola.getCollection("alunos", Aluno.class);
alunos.insertOne(aluno);
mongoClient.close();
}
}
Codigo da classe AlunoController:
package br.com.alura.escolaalura.escolaalura.controller;
import br.com.alura.escolaalura.escolaalura.model.Aluno; import br.com.alura.escolaalura.escolaalura.repository.AlunoRepository; 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;
@Controller public class AlunoController {
@Autowired
private AlunoRepository repository;
@GetMapping(value = "/aluno/cadastrar")
public String cadastrarAluno(Model model) {
model.addAttribute("aluno", new Aluno());
return "aluno/cadastrar";
}
@PostMapping("/aluno/salvar")
public String salvar(@ModelAttribute Aluno aluno) {
System.out.println("Aluno para salvar: " + aluno);
repository.salvar(aluno);
return "redirect:/";
}
}
Alguém conseguiria me ajudar a entender o porquê deste erro? Desde já agradeço!