Spring Boot控制器返回404



Spring Boot控制器在所有端点返回404

试图获得基本控制器返回数据包结构设置正确,所有包都是主包的子包注释看起来很好,我随意地使用了一下spring,但是我不知道,我期待至少是hello world,我假设它是一些spring垃圾,它没有找到bean,也没有运气找到任何常规配置之外的东西。请帮忙,谢谢

package com.bookieburglar.api.services;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//@EnableJpaRepositories(basePackages = "com.bookieburlgar.api.services")
@ComponentScan(basePackages = "com.bookieburglar.api.services")
@SpringBootApplication
public class BookieBurglarApplication {
public static void main(String[] args) {
SpringApplication.run(BookieBurglarApplication.class, args);
}
}

Odds.java

package com.bookieburglar.api.services.models;
import java.util.List;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class Odds {
@Id
@JsonProperty("id")
private String id;
@JsonProperty("sport_key")
private String sport_key;
@JsonProperty("sport_title")
private String sport_title;
@JsonProperty("commence_time")
private String commence_time;
@JsonProperty("home_team")
private String home_team;
@JsonProperty("away_team")
private String away_team;
@JsonProperty("bookmakers")
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "odds_id")
private List<Bookmaker> bookmakers;

public Odds(String id, String sportKey, String sportTitle, String commenceTime,
String homeTeam, String awayTeam, List<Bookmaker> bookmakers) {
this.id = id;
this.sport_key = sportKey;
this.sport_title = sportTitle;
this.commence_time = commenceTime;
this.home_team = homeTeam;
this.away_team = awayTeam;
this.bookmakers = bookmakers;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSportKey() {
return sport_key;
}
public void setSportKey(String sportKey) {
this.sport_key = sportKey;
}
public String getSportTitle() {
return sport_title;
}
public void setSportTitle(String sportTitle) {
this.sport_title = sportTitle;
}
public String getCommenceTime() {
return commence_time;
}
public void setCommenceTime(String commenceTime) {
this.commence_time = commenceTime;
}
public String getHomeTeam() {
return home_team;
}
public void setHomeTeam(String homeTeam) {
this.home_team = homeTeam;
}
public String getAwayTeam() {
return away_team;
}
public void setAwayTeam(String awayTeam) {
this.away_team = awayTeam;
}
public List<Bookmaker> getBookmakers() {
return bookmakers;
}
public void setBookmakers(List<Bookmaker> bookmakers) {
this.bookmakers = bookmakers;
}
}

OddsController

package com.bookieburglar.api.services.controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.bookieburglar.api.services.services.OddsAPIService;
import com.bookieburglar.api.services.services.OddsService;
import com.bookieburglar.api.services.models.Odds;
import com.bookieburglar.api.services.repositories.OddsRepository;
@RestController
@RequestMapping("/Odds")
public class OddsController {


@Autowired
private OddsService oddsService;





@Autowired
private OddsAPIService oddsAPIService;
@GetMapping("/")
public String getOdds() {
return "WORLD";
//return (List<Odds>) OddsRepository.findAll();
}
//    @GetMapping("/{id}")
//    public Odds getOdds(@PathVariable String id) {
//        return OddsRepository.findById(id).orElse(null);
//    }
@PostMapping("/create")
public Odds createOdds(@RequestBody Odds Odds) {
System.out.println("frthoo");
return oddsService.saveOdds(Odds);
}

@GetMapping("/refresh")
@ResponseBody
public String refreshOdds() {
System.out.println("ttgb5");
//return oddsAPIService.refreshOdds(); 
return "yoo";
}
//    @PutMapping("/{id}")
//    public Odds updateOdds(@PathVariable String id, @RequestBody Odds Odds) {
//        Odds.setId(id);
//        return OddsRepository.save(Odds);
//    }
//
//    @DeleteMapping("/{id}")
//    public void deleteOdds(@PathVariable String id) {
//        OddsRepository.deleteById(id);
//    }


}

OddsServices

package com.bookieburglar.api.services.services;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bookieburglar.api.services.models.Odds;
import com.bookieburglar.api.services.repositories.OddsRepository;
@Service
public class OddsService {

@Autowired
private OddsRepository oddsRepository;
public List<Odds> getAllOdds() {
return (List<Odds>) oddsRepository.findAll();
}
public Optional<Odds> findOddsById(String id) {
return oddsRepository.findById(id);
}
//    public List<Odds> findOddsBySportTitle(String sportTitle) {
//        return oddsRepository.findBySportTitle(sportTitle);
//    }
//
//    public List<Odds> findOddsByHomeTeam(String homeTeam) {
//        return oddsRepository.findByHomeTeam(homeTeam);
//    }
//    
//    public List<Odds> findOddsByAwayTeam(String awayTeam) {
//        return oddsRepository.findByAwayTeam(awayTeam);
//    }
public Odds saveOdds(Odds odds) {
return oddsRepository.save(odds);
}
public void deleteOdds(String id) {
oddsRepository.deleteById(id);
}
}

OddsRepository

package com.bookieburglar.api.services.repositories;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.bookieburglar.api.services.models.Odds;

@Repository
public interface OddsRepository extends JpaRepository<Odds, String> {


List<Odds> findAll();
// additional methods can be defined here, for example, to search for odds by sport key or teams 
}

pom.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>3.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.bookieburglar.api</groupId>
<artifactId>services</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Bookie Burglar</name>
<description>API for BookieBurglar</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>


<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>

<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

In@ComponentScan注释。包名不正确

@ComponentScan(basePackages = "com.bookieburlgar.api.services")

应该是

@ComponentScan(basePackages = "com.bookieburglar.api.services")

最新更新