【发布时间】:2020-02-24 08:52:01
【问题描述】:
服务
@Path("/rest")
public class JustService {
@GET
@Produces("text/plain")
@Path("sayhi")
public String sayhi(){
return "Hi";
}
}
应用程序配置
@ApplicationPath("/*")
public class ApplicationConfig extends Application {
}
Tomcat 在端口 8080 上运行,这是我发送的 Postman 请求:
localhost:8080/rest/sayhi
回复
"status": 404,
"error": "Not Found",
"message": "No message available",
这是 POM.XML:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
修复
任何遇到这个问题的人都可以解决这个问题->正如@cassiomolin所建议的那样
在您的ApplicationConfig 中将扩展类从Application 更改为-> ResourceConfig,然后添加:
@Component
public class JerseyConfig() extends ResourceConfig{
// I also changed the name of class to JerseyConfig (this is optional of course )
public JerseyConfig() {
register(JustService.class);
}
//change JustService to your service class and add as many register's as service classes you have.
// you can add @ApplicationPath annotation to this class if you need to
【问题讨论】: