找不到对 http://localhost:8082/{params} 的观察者的请求

Can't find the request for http://localhost:8082/{params}'s Observer

我这里有一个非常简单的JavaREST服务代码概念。

问题是,当我点击 URL 时,以下消息显示在控制台中: 找不到对 http://localhost:8082/REST/services/patientservices/getallpatients 的观察者的请求

我正在使用 cxf.jaxrs.component-scan=true 为 spring 阅读注释。

下面是类和配置文件:

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>2.3.11.RELEASE</version>
       <relativePath /> <!-- lookup parent from repository -->
    </parent>
<groupId>com.mayukh.rs</groupId>
<artifactId>jaxrs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jaxrs</name>
<description>JAX RS</description>
<properties>
    <java.version>1.8</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
        <version>3.4.2</version>
    </dependency>

    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.1.1</version>
    </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>

PatientService.java:

package com.mayukh.rs;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import com.mayukh.rs.model.Patient;

@Path("/patientservices")
public interface PatientService {

@Path("/getallpatients")
@GET
List<Patient> getPatients();
}

PatientServiceImpl.java:

package com.mayukh.rs;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.mayukh.rs.model.Patient;

@Service
public class PatientServiceImpl implements PatientService {
    
    Map<Long, Patient> patients = new HashMap<>();
    long currId = 123;
    
    public PatientServiceImpl() {
        
        init();
    }
    
    public void init() {
        Patient patient = new Patient();
        patient.setId(currId);
        patient.setName("Mayukh");
        patients.put(patient.getId(), patient);
    }

    @Override
    public List<Patient> getPatients() {
 
        Collection<Patient> results = patients.values();
        List<Patient> response = new ArrayList<>(results);
        
        return response;
    }

}

application.properties:

server.port=8082
cxf.jaxrs.component-scan=true
server.servlet.context-path=/REST

pom.xml 文件中有错误。

而不是 jaxws 依赖,它应该是 jaxrs 依赖。

<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
            <version>3.4.3</version>
        </dependency>