我已经完成了我的代码,但它不工作,我不能找到任何解决方案,任何帮助将得到认可
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);
}
}
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);
}
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);
}
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);
}
}
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 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>
请帮我解决这个错误
在weatherrepository
中,您有:
List<Weather> findByNameContaining(String value);
现在,这是一个派生的查询方法(这里更多)。
问题是weather
实体没有在方法中使用的名为name
的属性。
List<Weather> findByCityContaining(String value);
启动应用程序上下文时出错。若要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2020-08-05 09:53:05.348 错误 46991 --- [ 主] o.s.boot.Spring 应用程序: 应用程序运行失败 组织.Spring框架.豆子.工厂.不满意依赖性异常:创建名称为“产品控制器”的Bean时出错:通过字段“产品存储库”表示的不满意的依赖关系;嵌套的异常是组织.spri
我尝试使用Mybatis XML配置实现一个简单的CRUD应用程序已经是第三天了,我对整个Spring生态系统还是新手。这个问题有点长,但我只分享了要点。 我有一个类: 然后我写了一个映射器 在许多教程和解答之后,我创建了一个,文件也在`Resources文件夹中。 在中,我所做的与在文件中所做的几乎相同 以下是项目结构截图: 嵌套异常是org.springframework.beans.fact
我有这个错误已经有好几个星期了,我不知道如何修复它。类似的堆栈溢出解决方案不适合我的项目。 我目前使用mysql数据库,但遇到这个问题,每当试图启动服务器: StackTrace [错误]无法执行目标组织。springframework。boot:spring boot maven插件:1.5.6。发布:在project iPbackend上运行(默认cli):运行时发生异常。null:Invoc
创建名称为clienteRestController的bean时出错:通过字段clientService表示的不满意的依赖项。 创建名称为'clientServiceImpl'的bean时出错:通过字段'client道'表示的不满意的依赖项。 创建名称为ICliente道的bean时出错:初始化方法调用失败。 嵌套异常java.lang.IllegalArgumentExcishop:不是托管类型
我查了一些类似的问题,但这些答案帮不了我。 错误 组织。springframework。豆。工厂未满足的依赖项异常:创建名为“accountController”的bean时出错:未满足的依赖项通过字段“accountService”表示;嵌套的异常是org。springframework。豆。工厂NoSuchBeanDefinitionException:没有类型为“com”的合格bean。服务
我想在我的项目中实现Spring Security性。但不管我怎么做,我总是会犯同样的错误。 我创建了必要的类(,,)。它们在同一个包下,但我得到以下错误。 这是发生问题的的一部分 2018-12-31 23:58:10.616信息9952---[main]j.LocalContainerEntityManagerFactoryBean:初始化了持久性单元“默认”的JPA EntityManage