Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 错误控制程序Howto:Spring boot+;Spring数据休息_Java_Spring Boot_Spring Data Rest - Fatal编程技术网

Java 错误控制程序Howto:Spring boot+;Spring数据休息

Java 错误控制程序Howto:Spring boot+;Spring数据休息,java,spring-boot,spring-data-rest,Java,Spring Boot,Spring Data Rest,使用SpringDataREST的SpringBoot-如何使用自定义错误处理程序。 创建了一个错误控制器,我尝试使用以下代码跳过默认的错误处理程序。 为什么它不起作用 @Configuration @EnableJpaRepositories @Import(RepositoryRestMvcConfiguration.class) @EnableAutoConfiguration(exclude = { BasicErrorController.class }) @EnableMetrics

使用SpringDataREST的SpringBoot-如何使用自定义错误处理程序。 创建了一个错误控制器,我尝试使用以下代码跳过默认的错误处理程序。 为什么它不起作用

@Configuration
@EnableJpaRepositories
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration(exclude = { BasicErrorController.class })
@EnableMetrics

public class Application {
    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(Application.class, args);
        .....................
        .....................
和错误控制器如下所示

@Component
@RestController
@RequestMapping(value = "/error")
public class CustomErrorController extends BasicErrorController {

    public CustomErrorController(ErrorAttributes errorAttributes) {
        super(errorAttributes);
        // TODO Auto-generated constructor stub
    }

    private static final String PATH = "/error";

    @RequestMapping(value = PATH)
    public String error() {
        return "Error handling";
    }

    @Override
    public String getErrorPath() {
        return PATH;
    }
}

我没有使用这种解决方案,但是,您的请求映射似乎不正确

CustomErrorController的请求映射为'/error',在

@RequestMapping(value = PATH)
public String error() {
    return "Error handling";
}

请求映射路径中存在另一个“/error”。然后,此错误处理程序的url为“/error/error”。

控制器上有
@RequestMapping(“/error”)
注释,方法上有第二个
@RequestMapping(“/error”)
。这将导致
/error/error
映射,而不是在
getErrorPath()
方法中指定的
/error
映射,也可能是在配置中指定的映射(application.properties,server.path.error)