admin管理员组

文章数量:1122832

I'm sending the following request:

POST http://localhost:8080/bookings/newBooking
Content-Type: application/json
{
  "bookingId": 1,
  "user": {
    "userId": 3,
    "username": "user1",
    "password": "password1",
    "email": "[email protected]"
  },
  "paymentId": 4
}

And I get the following error

"org.springframework.web.servlet.resource.NoResourceFoundException: No static resource bookings/newBooking. org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:585).springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:52)...

BookingController:

package org.soa.booking;
@RestController
@RequestMapping("/bookings")
public class BookingController {

    private final BookingService bookingService;

    @Autowired
    public BookingController(BookingService bookingService) {
        this.bookingService = bookingService;
    }

    @PostMapping("/newBooking")
    public Booking createBooking(@RequestBody Booking booking) {
        return bookingService.createBooking(booking);
    }
}

SoaApplication:

package org.soa;
@SpringBootApplication
@RestController
public class SoaApplication {
    public static void main(String[] args){
        SpringApplication.run(SoaApplication.class, args);
    }

build.gradle:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.3.4'
    id 'io.spring.dependency-management' version '1.1.6'
}

group = 'org.soa'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'javax.persistence:javax.persistence-api:2.2'
    implementation 'org.mariadb.jdbc:mariadb-java-client:3.0.5'
}

sourceSets {
    main {
        java {
            exclude 'org/soa/passenger/**'
            exclude 'org/soa/flight/**'
            exclude 'org/soa/payment/**'
            exclude 'org/soa/airport/**'
        }
    }
}


tasks.named('test') {
    useJUnitPlatform()
}

From what I understand is that the Controller is being treated as a request for a static resource rather than being handled by the Controller. However, I don't know how to solve it, any insights highly appreciate it.

本文标签: springspringframeworkwebservletresourceNoResourceFoundException No static resourceStack Overflow