2016-08-03 8 views
7

私はSpringブートでAPIを作成しているので、/errorマッピングを無効にしたいと考えています。スプリングブート無効/エラーマッピング

私はapplication.propertiesで次の小道具を設定している:私は/errorを打ったとき

server.error.whitelabel.enabled=false 
spring.mvc.throw-exception-if-no-handler-found=true 
spring.resources.add-mappings=false 

は、しかし、私は得る:

HTTP/1.1 500 Internal Server Error 
Server: Apache-Coyote/1.1 
Content-Type: application/json;charset=UTF-8 
Transfer-Encoding: chunked 
Date: Wed, 03 Aug 2016 15:15:31 GMT 
Connection: close 

{"timestamp":1470237331487,"status":999,"error":"None","message":"No message available"} 

必要な結果

HTTP/1.1 404 Internal Server Error 
Server: Apache-Coyote/1.1 

答えて

15

することができますErrorMvcAutoConfigurationを無効にする:

@SpringBootApplication 
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class}) 
public class SpringBootLauncher { 

それとも春ブーツのapplication.yml /プロパティを通じて:

spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration 

これはあなたのためのオプションではない場合、あなたはまた、独自の実装とSpringののErrorControllerを延長することができる:

@RestController 
public class MyErrorController implements ErrorController { 

    private static final String ERROR_MAPPING = "/error"; 

    @RequestMapping(value = ERROR_MAPPING) 
    public ResponseEntity<String> error() { 
     return new ResponseEntity<String>(HttpStatus.NOT_FOUND); 
    } 

    @Override 
    public String getErrorPath() { 
     return ERROR_MAPPING; 
    } 
+2

ええ、私はちょうど迷惑であるこの正確なことをしました!もしバインドを取り除く方法があるのであれば、これを行わずに – ptimson

+0

同じように、私はそれをすべて削除したら、今度はjsonの代わりにhtmlになります... – TheBakker

0

私の場合は、ログインページのヘッダーで参照されているWebリソースに問題がありました。具体的には、ヘッダーでcssが参照されましたが、実際にはプロジェクトに存在しませんでした。

私のWebSecurityConfigurerAdapter実装では、先にconfigure(WebSecurity web)の本文をコメントアウトしてから、上記のエラーjsonを表示する代わりにログインしようとしました。私のブラウザのアドレスバーは、問題を引き起こしているリソース。

関連する問題