Я пытаюсь разработать basi c Spring Boot REST API CRUD с Spring Data H2
Ошибка:
org.springframework.beans.factory.UnsatisfiedDependencyException: Ошибка при создании bean-компонента с именем «weatherController»: неудовлетворенная зависимость, выраженная через поле «weatherService»; вложенное исключение - org.springframework.beans.factory.UnsatisfiedDependencyException: ошибка при создании bean-компонента с именем «weatherService»: неудовлетворенная зависимость, выраженная через поле «weatherRepository»; вложенное исключение - org.springframework.beans.factory.BeanCreationException: ошибка создания bean-компонента с именем 'weatherRepository': не удалось вызвать метод инициализации; вложенное исключение: java .lang.IllegalArgumentException: не удалось создать запрос для метода publi c abstract java .util.List com.example.springboot2.WeatherRepository.findByNameConpting (java .lang.String)! Не найдено имя свойства для типа Weather!
Я закончил свой код, но он не работает, и я не могу найти никакого решения, любая помощь будет оказана
Weather. java
package com.example.springboot2;
import org.springframework.stereotype.Component;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDate;
@Entity
public class Weather {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)// Otomatik oluşturulmasın
private long id;
private String city;
private LocalDate dateMeasured;
private double tempMin;
private double tempMax;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public LocalDate getDateMeasured() {
return dateMeasured;
}
public void setDateMeasured(LocalDate dateMeasured) {
this.dateMeasured = dateMeasured;
}
public double getTempMin() {
return tempMin;
}
public void setTempMin(double tempMin) {
this.tempMin = tempMin;
}
public double getTempMax() {
return tempMax;
}
public void setTempMax(double tempMax) {
this.tempMax = tempMax;
}
}
WeatherController. java
package com.example.springboot2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/weather")
public class WeatherController{
@Autowired
private WeatherService weatherService;
@GetMapping()
public ResponseEntity<List<Weather>> getAllWeathers() {
List<Weather> weatherList = weatherService.getAllWeathers();
return new ResponseEntity<>(weatherList, HttpStatus.OK);
}
@GetMapping("/{id}")
public ResponseEntity<Weather> getWeatherById(
@PathVariable("id") final Long id) {
Weather weather = weatherService.getWeatherById(id);
return new ResponseEntity<>(weather, HttpStatus.OK);
}
@PostMapping()
public ResponseEntity<Weather> saveWeather(
@RequestBody final Weather weather) {
Weather savedWeather = weatherService.saveWeather(weather);
return new ResponseEntity<>(savedWeather, HttpStatus.CREATED);
}
@PutMapping("/{id}")
public ResponseEntity<Weather> updateWeatherById(
@PathVariable("id") final Long id,
@RequestBody final Weather weatherToUpdate) {
Weather updatedWeather
= weatherService.updateWeatherById(id, weatherToUpdate);
return new ResponseEntity<>(updatedWeather, HttpStatus.OK);
}
@DeleteMapping("/{id}")
public ResponseEntity<String> deleteWeatherById(
@PathVariable("id") final Long id) {
weatherService.deleteWeatherById(id);
return new ResponseEntity<>("Success", HttpStatus.OK);
}
@GetMapping("/search1/{searchString}")
public ResponseEntity<List<Weather>> getWeatherByNameContaining(
@PathVariable("searchString") final String searchString) {
List<Weather> weatherList
= weatherService.getWeatherByNameContaining(searchString);
return new ResponseEntity<>(weatherList, HttpStatus.OK);
}
@GetMapping("/search2/{searchString}")
public ResponseEntity<List<Weather>> getWeatherByNameLike(
@PathVariable("searchString") final String searchString) {
List<Weather> weatherList
= weatherService.getWeatherByNameLike(searchString);
return new ResponseEntity<>(weatherList, HttpStatus.OK);
}
}
WeatherRepository
package com.example.springboot2;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import java.util.List;
public interface WeatherRepository extends CrudRepository<Weather,Long> {
List<Weather> findByNameContaining(String value);
@Query("SELECT w FROM Weather w WHERE w.city LIKE %:value%")
List<Weather> findByNameLike(@Param("value") String value);
}
WeatherService
package com.example.springboot2;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("weatherService")
public interface WeatherService {
List<Weather> getAllWeathers();
Weather getWeatherById(Long id);
Weather saveWeather(Weather weather);
Weather updateWeatherById(Long id, Weather weatherToUpdate);
void deleteWeatherById(Long id);
List<Weather> getWeatherByNameContaining(String searchString);
List<Weather> getWeatherByNameLike(String searchString);
}
WeatherServiceImpl
package com.example.springboot2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.List;
@Component
@Service("weatherService")
public class WeatherServiceImpl implements WeatherService {
@Autowired
private WeatherRepository weatherRepository;
@Override
public List<Weather> getAllWeathers() {
return (List<Weather>) weatherRepository.findAll();
}
@Override
public Weather getWeatherById(final Long id) {
return weatherRepository.findById(id).get();
}
@Override
public Weather saveWeather(final Weather weather) {
return weatherRepository.save(weather);
}
@Override
public Weather updateWeatherById(
final Long id, final Weather weatherToUpdate) {
Weather weatherFromDb = weatherRepository.findById(id).get();
weatherFromDb.setCity(weatherToUpdate.getCity());
weatherFromDb.setDateMeasured(weatherToUpdate.getDateMeasured());
weatherFromDb.setTempMax(weatherToUpdate.getTempMax());
weatherFromDb.setTempMin(weatherToUpdate.getTempMin());
return weatherRepository.save(weatherFromDb);
}
@Override
public void deleteWeatherById(final Long id) {
weatherRepository.deleteById(id);
}
@Override
public List<Weather> getWeatherByNameContaining(final String searchString) {
return weatherRepository.findByNameContaining(searchString);
}
@Override
public List<Weather> getWeatherByNameLike(final String searchString) {
return weatherRepository.findByNameLike(searchString);
}
}
Springboot2Application
package com.example.springboot2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@ComponentScan("com.example")
public class Springboot2Application {
public static void main(String[] args) {
SpringApplication.run(Springboot2Application.class, args);
}
}
пом. 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.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springboot2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot2</name>
<description>Demo project for Spring Boot</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-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</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>
Пожалуйста, помогите мне решить ошибку