URL: «localhost: 8082 / api / notebooks / all» должен достигать метода контроллера, но он показывает ошибку белой метки с сообщением о явной проблеме сопоставления приложения. Есть ли проблемы с пакетом war?
Контроллер:
package com.savenotes.controller;
import java.util.List;
import java.util.UUID;
import javax.validation.Valid;
import javax.validation.ValidationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.savenotes.model.Notebook;
import com.savenotes.repository.NotebookRepository;
import com.savenotes.savenotes.Mapper;
import com.savenotes.viewmodel.NotebookViewModel;
@RestController
@RequestMapping("/api/notebooks")
@CrossOrigin
public class NoteBookController
{
@Autowired
private NotebookRepository notebookRepository;
@Autowired
private Mapper mapper;
public NoteBookController(NotebookRepository notebookRepository, Mapper mapper)
{
this.notebookRepository = notebookRepository;
this.mapper = mapper;
}
@GetMapping("/all")
public List<Notebook> fetchAllNotebook()
{
List<Notebook> listOfNotebooks = notebookRepository.findAll();
System.out.println("Hiiiiiiii");
return listOfNotebooks;
}
@PostMapping
public Notebook save(@Valid @RequestBody NotebookViewModel notebookViewModel,
BindingResult bindingResult)
{
if(bindingResult.hasErrors())
{
throw new ValidationException();
}
Notebook notebook = mapper.convertToNotebookEntity(notebookViewModel);
notebookRepository.save(notebook);
return notebook;
}
@DeleteMapping("/{id}")
public void delete(@PathVariable String id)
{
notebookRepository.deleteById(UUID.fromString(id));
}
}
Номер порта указан в файле application.properties.
Application.properties:
spring.datasource.url=jdbc:h2:file:./asdj.db
noteit.db.recreate=true
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=
spring.mail.password=
server.port=8082
Этот проект был создан в войне с версией java8. Я думаю, что я включил все необходимые зависимости
pom. xml file:
<?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.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.savenotes</groupId>
<artifactId>savenotes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>savenotes</name>
<description>Project to save notes</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>