ПРИМЕЧАНИЕ: - Отредактировано Некоторые опечатки
Я пытаюсь подключить мое приложение для весенней загрузки с атласом Mon go. Я настроил Atlas, я также могу подключиться к Atlas через Mon go compass и создал базу данных с коллекцией через canvas. Затем я скопировал URI из вкладки подключения Atlas, выбранной в качестве драйвера, java, попробовал все версии, указанные один за другим, но ничего не получалось. мой код выглядит следующим образом.
мой контроллер
@GetMapping("/candidate")
public String getCandidate(Model model){
model.addAttribute("cdto", new CandidateDto());
return "candidate";
}
@PostMapping("candidate")
public String postCandidate(@ModelAttribute ("cdto") @Valid CandidateDto cdto){
cservice.addCandidate(cdto);
return "redirect:/candidate";
}
вот мой класс сущностей
import lombok.Data;
@Data
@Document(collection="candidate")
public class Candidate {
private String name;
private String age;
private String branch;
private String institute;
private String pasout;
private String mobile;
private String email;
private String tenth;
private String wealth;
private String degree;
}
вот мой класс дто
import lombok.Data;
@Data
public class CandidateDto {
private String name;
private String age;
private String branch;
private String institute;
private String pasout;
private String mobile;
private String email;
private String tenth;
private String wealth;
private String degree;
}
вот мой репозиторий
public interface CandidateRepository extends MongoRepository<Candidate, String> {
}
вот мой сервис реализации
@Override
public void addCandidate(CandidateDto cdto) {
Candidate ca=new Candidate();
ca.setName(cdto.getName());
ca.setAge(cdto.getAge());
ca.setBranch(cdto.getBranch());
ca.setDegree(cdto.getDegree());
ca.setEmail(cdto.getEmail());
ca.setInstitute(cdto.getInstitute());
ca.setMobile(cdto.getMobile());
ca.setPasout(cdto.getPasout());
ca.setTenth(cdto.getTenth());
ca.setTwelth(cdto.getTwelth());
crepo.save(ca);
}
и это мое application.properties
spring.data.mongodb.database=ndtcdb
spring.data.mongodb.uri=mongodb://myadmin:mypassword@cluster0-shard-00-00-vfmqk.mongodb.net:27017,cluster0-shard-00-01-vfmqk.mongodb.net:27017,cluster0-shard-00-02-vfmqk.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority
Редактировать: - добавив этот код для моего класса приложения
@SpringBootApplication
public class NdtcApplication {
public static void main(String[] args) {
SpringApplication.run(NdtcApplication.class, args);
}
}
и ниже мой pom. xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</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.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</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>
</dependencies>
, и это ошибка, которую я получаю
java.lang.NoClassDefFoundError: com/mongodb/MongoCredential
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:1.8.0_161]
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) ~[na:1.8.0_161]
at java.lang.Class.getDeclaredConstructors(Unknown Source) ~[na:1.8.0_161]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.findConstructorBindingAnnotatedConstructor(ConfigurationPropertiesBindConstructorProvider.java:62) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.getBindConstructor(ConfigurationPropertiesBindConstructorProvider.java:48) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBean$BindMethod.forType(ConfigurationPropertiesBean.java:311) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.validate(ConfigurationPropertiesBeanDefinitionValidator.java:63) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.postProcessBeanFactory(ConfigurationPropertiesBeanDefinitionValidator.java:45) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:174) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at com.ndtc.NdtcApplication.main(NdtcApplication.java:10) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_161]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.6.RELEASE.jar:2.2.6.RELEASE]
Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoCredential
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_161]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
... 24 common frames omitted
Пожалуйста, помогите , Прошло 3 дня, я борюсь, но не могу решить