returning all result using spring-data-rest












0















I am following spring data rest from https://spring.io/guides/gs/accessing-data-rest/ and I am only using



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>


I would like to know how can I return all records (without pagination) but not using spring-boot-starter-web.I wants to keep my code as small as possible.



I tried following but it is not working



@RepositoryRestResource(collectionResourceRel = "people" , path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
List<Person> findAllByLastName(@Param("name") String name);
default List<Person> findAll(){
Pageable pageable = null;
return (List<Person>) this.findAll(pageable);
};
}


I mean if I have whole MVC, I can do it but I like to keep my code to minimum.










share|improve this question

























  • Can you clarify your question? You say you're trying to use "spring-boot-data-rest", but you want to use that without using the "web" starter? There is no "spring-boot-data-rest" dependency, only the "starter" (spring-boot-starter-data-rest), which itself includes Spring MVC. So no matter what, if you're using Spring Data REST, you're including Spring MVC as well. Do you want a REST endpoint, but no paging? Or something else?

    – Ted M. Young
    Nov 18 '18 at 22:22













  • @TedM.Young I have corrected my question. I want a REST endpoint but no paging.

    – ashish
    Nov 19 '18 at 3:05
















0















I am following spring data rest from https://spring.io/guides/gs/accessing-data-rest/ and I am only using



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>


I would like to know how can I return all records (without pagination) but not using spring-boot-starter-web.I wants to keep my code as small as possible.



I tried following but it is not working



@RepositoryRestResource(collectionResourceRel = "people" , path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
List<Person> findAllByLastName(@Param("name") String name);
default List<Person> findAll(){
Pageable pageable = null;
return (List<Person>) this.findAll(pageable);
};
}


I mean if I have whole MVC, I can do it but I like to keep my code to minimum.










share|improve this question

























  • Can you clarify your question? You say you're trying to use "spring-boot-data-rest", but you want to use that without using the "web" starter? There is no "spring-boot-data-rest" dependency, only the "starter" (spring-boot-starter-data-rest), which itself includes Spring MVC. So no matter what, if you're using Spring Data REST, you're including Spring MVC as well. Do you want a REST endpoint, but no paging? Or something else?

    – Ted M. Young
    Nov 18 '18 at 22:22













  • @TedM.Young I have corrected my question. I want a REST endpoint but no paging.

    – ashish
    Nov 19 '18 at 3:05














0












0








0








I am following spring data rest from https://spring.io/guides/gs/accessing-data-rest/ and I am only using



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>


I would like to know how can I return all records (without pagination) but not using spring-boot-starter-web.I wants to keep my code as small as possible.



I tried following but it is not working



@RepositoryRestResource(collectionResourceRel = "people" , path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
List<Person> findAllByLastName(@Param("name") String name);
default List<Person> findAll(){
Pageable pageable = null;
return (List<Person>) this.findAll(pageable);
};
}


I mean if I have whole MVC, I can do it but I like to keep my code to minimum.










share|improve this question
















I am following spring data rest from https://spring.io/guides/gs/accessing-data-rest/ and I am only using



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>


I would like to know how can I return all records (without pagination) but not using spring-boot-starter-web.I wants to keep my code as small as possible.



I tried following but it is not working



@RepositoryRestResource(collectionResourceRel = "people" , path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
List<Person> findAllByLastName(@Param("name") String name);
default List<Person> findAll(){
Pageable pageable = null;
return (List<Person>) this.findAll(pageable);
};
}


I mean if I have whole MVC, I can do it but I like to keep my code to minimum.







java spring spring-boot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 3:04







ashish

















asked Nov 17 '18 at 12:59









ashishashish

8,014114984




8,014114984













  • Can you clarify your question? You say you're trying to use "spring-boot-data-rest", but you want to use that without using the "web" starter? There is no "spring-boot-data-rest" dependency, only the "starter" (spring-boot-starter-data-rest), which itself includes Spring MVC. So no matter what, if you're using Spring Data REST, you're including Spring MVC as well. Do you want a REST endpoint, but no paging? Or something else?

    – Ted M. Young
    Nov 18 '18 at 22:22













  • @TedM.Young I have corrected my question. I want a REST endpoint but no paging.

    – ashish
    Nov 19 '18 at 3:05



















  • Can you clarify your question? You say you're trying to use "spring-boot-data-rest", but you want to use that without using the "web" starter? There is no "spring-boot-data-rest" dependency, only the "starter" (spring-boot-starter-data-rest), which itself includes Spring MVC. So no matter what, if you're using Spring Data REST, you're including Spring MVC as well. Do you want a REST endpoint, but no paging? Or something else?

    – Ted M. Young
    Nov 18 '18 at 22:22













  • @TedM.Young I have corrected my question. I want a REST endpoint but no paging.

    – ashish
    Nov 19 '18 at 3:05

















Can you clarify your question? You say you're trying to use "spring-boot-data-rest", but you want to use that without using the "web" starter? There is no "spring-boot-data-rest" dependency, only the "starter" (spring-boot-starter-data-rest), which itself includes Spring MVC. So no matter what, if you're using Spring Data REST, you're including Spring MVC as well. Do you want a REST endpoint, but no paging? Or something else?

– Ted M. Young
Nov 18 '18 at 22:22







Can you clarify your question? You say you're trying to use "spring-boot-data-rest", but you want to use that without using the "web" starter? There is no "spring-boot-data-rest" dependency, only the "starter" (spring-boot-starter-data-rest), which itself includes Spring MVC. So no matter what, if you're using Spring Data REST, you're including Spring MVC as well. Do you want a REST endpoint, but no paging? Or something else?

– Ted M. Young
Nov 18 '18 at 22:22















@TedM.Young I have corrected my question. I want a REST endpoint but no paging.

– ashish
Nov 19 '18 at 3:05





@TedM.Young I have corrected my question. I want a REST endpoint but no paging.

– ashish
Nov 19 '18 at 3:05












2 Answers
2






active

oldest

votes


















0















Spring Data REST is itself a Spring MVC application and is designed in
such a way that it should integrate with your existing Spring MVC
applications with little effort. An existing (or future) layer of
services can run alongside Spring Data REST with only minor additional
work.






If you are using current version of spring boot, there is no need to mark your repository with @RepositoryRestResource; also spring will auto-configure Spring Data Rest once it found the spring-data-rest dependency in your path, bellow you will find steps with minimum config :



In pom.xml :



        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>


Define your Entity + Repository :



Order.java



@Entity(name = "SampleOrder")
@Data
public class Order {

@Id @GeneratedValue//
private Long id;
private String name;
}


OrderRepository.java



public interface OrderRepository extends CrudRepository<Order, Long> {

}


Application.java



@SpringBootApplication
public class Application {

public static void main(String args) {
SpringApplication.run(Application.class, args);
}
}


Test your API :



curl http://localhost:8080
< HTTP/1.1 200 OK
< Content-Type: application/hal+json
{ "_links" : {
"orders" : {
"href" : "http://localhost:8080/orders"
}
}
}





share|improve this answer
























  • Thanks but this still did not answer my question.

    – ashish
    Nov 17 '18 at 20:41



















0














As @abdelghani-roussi shows, you can use the CrudRepository instead of the PagingAndSortingRepository, e.g.:



public interface PersonRepository extends CrudRepository<Person, Long> {
List<Person> findAllByLastName(@Param("name") String name);
// don't need to define findAll(), it's defined by CrudRepository
}


and then the default findAll() method will return a List<Person> that isn't paged.



Note: as I mentioned in my comment, by including the dependency on spring-boot-starter-data-rest you are also pulling in the Web dependencies, so you can't avoid that.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351475%2freturning-all-result-using-spring-data-rest%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    Spring Data REST is itself a Spring MVC application and is designed in
    such a way that it should integrate with your existing Spring MVC
    applications with little effort. An existing (or future) layer of
    services can run alongside Spring Data REST with only minor additional
    work.






    If you are using current version of spring boot, there is no need to mark your repository with @RepositoryRestResource; also spring will auto-configure Spring Data Rest once it found the spring-data-rest dependency in your path, bellow you will find steps with minimum config :



    In pom.xml :



            <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    </dependency>


    Define your Entity + Repository :



    Order.java



    @Entity(name = "SampleOrder")
    @Data
    public class Order {

    @Id @GeneratedValue//
    private Long id;
    private String name;
    }


    OrderRepository.java



    public interface OrderRepository extends CrudRepository<Order, Long> {

    }


    Application.java



    @SpringBootApplication
    public class Application {

    public static void main(String args) {
    SpringApplication.run(Application.class, args);
    }
    }


    Test your API :



    curl http://localhost:8080
    < HTTP/1.1 200 OK
    < Content-Type: application/hal+json
    { "_links" : {
    "orders" : {
    "href" : "http://localhost:8080/orders"
    }
    }
    }





    share|improve this answer
























    • Thanks but this still did not answer my question.

      – ashish
      Nov 17 '18 at 20:41
















    0















    Spring Data REST is itself a Spring MVC application and is designed in
    such a way that it should integrate with your existing Spring MVC
    applications with little effort. An existing (or future) layer of
    services can run alongside Spring Data REST with only minor additional
    work.






    If you are using current version of spring boot, there is no need to mark your repository with @RepositoryRestResource; also spring will auto-configure Spring Data Rest once it found the spring-data-rest dependency in your path, bellow you will find steps with minimum config :



    In pom.xml :



            <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    </dependency>


    Define your Entity + Repository :



    Order.java



    @Entity(name = "SampleOrder")
    @Data
    public class Order {

    @Id @GeneratedValue//
    private Long id;
    private String name;
    }


    OrderRepository.java



    public interface OrderRepository extends CrudRepository<Order, Long> {

    }


    Application.java



    @SpringBootApplication
    public class Application {

    public static void main(String args) {
    SpringApplication.run(Application.class, args);
    }
    }


    Test your API :



    curl http://localhost:8080
    < HTTP/1.1 200 OK
    < Content-Type: application/hal+json
    { "_links" : {
    "orders" : {
    "href" : "http://localhost:8080/orders"
    }
    }
    }





    share|improve this answer
























    • Thanks but this still did not answer my question.

      – ashish
      Nov 17 '18 at 20:41














    0












    0








    0








    Spring Data REST is itself a Spring MVC application and is designed in
    such a way that it should integrate with your existing Spring MVC
    applications with little effort. An existing (or future) layer of
    services can run alongside Spring Data REST with only minor additional
    work.






    If you are using current version of spring boot, there is no need to mark your repository with @RepositoryRestResource; also spring will auto-configure Spring Data Rest once it found the spring-data-rest dependency in your path, bellow you will find steps with minimum config :



    In pom.xml :



            <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    </dependency>


    Define your Entity + Repository :



    Order.java



    @Entity(name = "SampleOrder")
    @Data
    public class Order {

    @Id @GeneratedValue//
    private Long id;
    private String name;
    }


    OrderRepository.java



    public interface OrderRepository extends CrudRepository<Order, Long> {

    }


    Application.java



    @SpringBootApplication
    public class Application {

    public static void main(String args) {
    SpringApplication.run(Application.class, args);
    }
    }


    Test your API :



    curl http://localhost:8080
    < HTTP/1.1 200 OK
    < Content-Type: application/hal+json
    { "_links" : {
    "orders" : {
    "href" : "http://localhost:8080/orders"
    }
    }
    }





    share|improve this answer














    Spring Data REST is itself a Spring MVC application and is designed in
    such a way that it should integrate with your existing Spring MVC
    applications with little effort. An existing (or future) layer of
    services can run alongside Spring Data REST with only minor additional
    work.






    If you are using current version of spring boot, there is no need to mark your repository with @RepositoryRestResource; also spring will auto-configure Spring Data Rest once it found the spring-data-rest dependency in your path, bellow you will find steps with minimum config :



    In pom.xml :



            <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    </dependency>


    Define your Entity + Repository :



    Order.java



    @Entity(name = "SampleOrder")
    @Data
    public class Order {

    @Id @GeneratedValue//
    private Long id;
    private String name;
    }


    OrderRepository.java



    public interface OrderRepository extends CrudRepository<Order, Long> {

    }


    Application.java



    @SpringBootApplication
    public class Application {

    public static void main(String args) {
    SpringApplication.run(Application.class, args);
    }
    }


    Test your API :



    curl http://localhost:8080
    < HTTP/1.1 200 OK
    < Content-Type: application/hal+json
    { "_links" : {
    "orders" : {
    "href" : "http://localhost:8080/orders"
    }
    }
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 17 '18 at 19:11









    Abdelghani RoussiAbdelghani Roussi

    98211024




    98211024













    • Thanks but this still did not answer my question.

      – ashish
      Nov 17 '18 at 20:41



















    • Thanks but this still did not answer my question.

      – ashish
      Nov 17 '18 at 20:41

















    Thanks but this still did not answer my question.

    – ashish
    Nov 17 '18 at 20:41





    Thanks but this still did not answer my question.

    – ashish
    Nov 17 '18 at 20:41













    0














    As @abdelghani-roussi shows, you can use the CrudRepository instead of the PagingAndSortingRepository, e.g.:



    public interface PersonRepository extends CrudRepository<Person, Long> {
    List<Person> findAllByLastName(@Param("name") String name);
    // don't need to define findAll(), it's defined by CrudRepository
    }


    and then the default findAll() method will return a List<Person> that isn't paged.



    Note: as I mentioned in my comment, by including the dependency on spring-boot-starter-data-rest you are also pulling in the Web dependencies, so you can't avoid that.






    share|improve this answer




























      0














      As @abdelghani-roussi shows, you can use the CrudRepository instead of the PagingAndSortingRepository, e.g.:



      public interface PersonRepository extends CrudRepository<Person, Long> {
      List<Person> findAllByLastName(@Param("name") String name);
      // don't need to define findAll(), it's defined by CrudRepository
      }


      and then the default findAll() method will return a List<Person> that isn't paged.



      Note: as I mentioned in my comment, by including the dependency on spring-boot-starter-data-rest you are also pulling in the Web dependencies, so you can't avoid that.






      share|improve this answer


























        0












        0








        0







        As @abdelghani-roussi shows, you can use the CrudRepository instead of the PagingAndSortingRepository, e.g.:



        public interface PersonRepository extends CrudRepository<Person, Long> {
        List<Person> findAllByLastName(@Param("name") String name);
        // don't need to define findAll(), it's defined by CrudRepository
        }


        and then the default findAll() method will return a List<Person> that isn't paged.



        Note: as I mentioned in my comment, by including the dependency on spring-boot-starter-data-rest you are also pulling in the Web dependencies, so you can't avoid that.






        share|improve this answer













        As @abdelghani-roussi shows, you can use the CrudRepository instead of the PagingAndSortingRepository, e.g.:



        public interface PersonRepository extends CrudRepository<Person, Long> {
        List<Person> findAllByLastName(@Param("name") String name);
        // don't need to define findAll(), it's defined by CrudRepository
        }


        and then the default findAll() method will return a List<Person> that isn't paged.



        Note: as I mentioned in my comment, by including the dependency on spring-boot-starter-data-rest you are also pulling in the Web dependencies, so you can't avoid that.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 22:50









        Ted M. YoungTed M. Young

        720717




        720717






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351475%2freturning-all-result-using-spring-data-rest%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith