Spring未拾取RestController终结点
我有如下所示的spring项目设置,但在/custom端点上有一个404。我发现的所有与此问题类似的答案都强调了控制器层需要位于项目层下面的包中,但是我将其设置为这样,因此我不确定Spring为什么不能识别端点Spring未拾取RestController终结点,spring,spring-boot,Spring,Spring Boot,我有如下所示的spring项目设置,但在/custom端点上有一个404。我发现的所有与此问题类似的答案都强调了控制器层需要位于项目层下面的包中,但是我将其设置为这样,因此我不确定Spring为什么不能识别端点 package com.myproject.controller; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.spring
package com.myproject.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("custom")
public class CustomPathController {
@GetMapping
public ResponseEntity<Void> test() {
return new ResponseEntity<>(HttpStatus.OK);
}
}
由于电脑重启修复了此问题,因此一定发生了端口冲突您好,您可以发布项目的结构吗?可能您的控制器类没有被Spring扫描和实例化。我用一个相同的包结构尝试了它,只是使用了不同的名称,它工作了,pom中包含了哪些依赖项?@user3240544我尝试添加ComponentScan(“com.myproject”)对于runner类,Intellij告诉我这是一个冗余注释,因为SpringBootApplication正在应用annotation@dariosicilylombok,spring boot starter jpa,postgresql,spring boot配置处理器,spring boot starter执行器,spring boot starter日志,spring boot starter Web我正在使用,我认为错误是由于缺少
spring boot starter thymeleaf
。
package com.myproject;
import com.ryantenney.metrics.spring.config.annotation.EnableMetrics;
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;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableMetrics
@EnableJpaRepositories
@SpringBootApplication
public class MyProject {
public static void main(String[] args) {
SpringApplication.run(MyProject.class, args);
}
}