2017-09-25 27 views
0

我正在創建一個彈簧啓動應用程序。我增加了幾個端點。在這個過程中,一些端點是安全的,有些則不是。額外的未知端點被添加到彈簧啓動應用程序

一旦安裝了應用程序,我得到了一些額外的端點給予甚至沒有暴露的應用程序信息。

舉例: 一些暴露的端點是

@RestController 
@RequestMapping("/category/v1") 
public class ControllerClass { 
    @RequestMapping(value="/pillars", method=RequestMethod.GET) 
    public String pillarGetMethod() { 
     //method 
    } 

    @RequestMapping(value="/frameworks", method=RequestMethod.GET) 
    public String frameworkGetMethod() { 
     //method 
    } 
} 

現在期望是,我們將有

  • /分類/ V1 /支柱
  • /分類/ V1 /框架

應該暴露。

但與

  • /支柱
  • /框架

也越來越暴露出與響應,

{ 
    "_embedded" : { 
    "pillars" : [ { 

    } ] 
    }, 
    "_links" : { 
    "self" : { 
     "href" : "http://<ip>/pillars{?page,size,sort}", 
     "templated" : true 
    }, 
    "profile" : { 
     "href" : "http://<ip>/profile/pillars" 
    }, 
    "search" : { 
     "href" : "http://<ip>/pillars/search" 
    } 
    }, 
    "page" : { 
    "size" : 20, 
    "totalElements" : 5, 
    "totalPages" : 1, 
    "number" : 0 
    } 
} 

我需要幫助的理解輸出以及如何我可以阻止它暴露。

+2

您是否定義了類似擴展CrudRepository的PillarRepository和Framework類?如果是這樣,除非使用'@RepositoryRestResource(exported = false)'註解存儲庫,否則底層資源會自動暴露在Spring Boot/Spring Data Rest中。 –

+0

非常感謝@Marc。它解決了這個問題。請將答覆添加爲答案,我將非常樂意接受答案作爲正確答案。 – Shaleen

回答

1

我的猜測是你定義是這樣的:

public class PillarRepository extends CrudRepository<Pillar, String> { ... } 

public class FrameworkPillarRepository extends CrudRepository<Pillar, String> { ... } 

如果是這樣,底層資源由Spring啓動/彈簧數據休息自動曝光,除非你@RepositoryRestResource(exported = false)註釋庫。

如果您只是希望重現自動GET行爲,但使用自定義路徑,請使用path選項。

相關問題