2017-08-13 27 views
2

刚学springboot(和新望到Java:从.NET世界)JPA库和Spring数据剩下的基本URI是/轮廓

太PS当然在弹簧的数据和弹簧数据休息。一切顺利

与MS SQlServer进行了测试项目连接。创建了几个JPA Repos并通过了FindAll的单元测试

我没有在应用程序属性中设置base-uri,并且在探索剩余界面(使用邮递员时)时,所有内容都显示在/ profile下。

{ 
    "_links": { 
     "self": { 
      "href": "http://localhost:8080/profile" 
     }, 
     "users": { 
      "href": "http://localhost:8080/profile/users" 
     }, 
     "tasks": { 
      "href": "http://localhost:8080/profile/tasks" 
     } 
    } 
} 

第一个问题是,/ profile是从哪里来的?

+0

在项目中搜索'@ RequestMapping'。 –

回答

1

这不是基本路径(url)。这是一个normal work of SDR

如果您导航到配置文件的链接位于localhost:8080/profile文件,你会看到这样的事情:

{ 
    "_links" : { 
    "self" : { 
     "href" : "http://localhost:8080/profile" 
    }, 
    "persons" : { 
     "href" : "http://localhost:8080/profile/persons" 
    }, 
    "addresses" : { 
     "href" : "http://localhost:8080/profile/addresses" 
    } 
    } 
} 

要与你的实体工作,你必须使用thees链接:

http://localhost:8080/users 
http://localhost:8080/tasks 

通过您可以在three ways设置 '基本路径' 的方式:

  1. 在“application.properties`

spring.data.rest.basePath=/api

  • 注册一个豆
  • @Bean 
    public RepositoryRestConfigurer repositoryRestConfigurer() { 
    
        return new RepositoryRestConfigurerAdapter() { 
    
        @Override 
        public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { 
         config.setBasePath("/api"); 
        } 
        }; 
    } 
    
  • 定制实施RepositoryRestConfigurer
  • @Component 
    public class CustomizedRestMvcConfiguration extends RepositoryRestConfigurerAdapter { 
    
        @Override 
        public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { 
        config.setBasePath("/api"); 
        } 
    } 
    
    +0

    非常感谢细节 – mark1234