• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

simple REST with Spring example

 
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking for a simple REST (may be even plain text) with SPRING. a tutorial example to biuld on Eclipse together with JUNIT.

From scratch.
An example of pure REST + SPRING (MVC).

Now I use Java 8, Eclipse Neon.3 Release (4.6.3) and Tomcat v8.5. MAVEN of course. All on Windows 10.

I have developed many REST utilities but never from scratch and for my own. They were built in a complex system of my employer.

I would like to build and observe it step by step.

I will appreciate a link to an example or hint where to find.
 
Bartender
Posts: 1155
20
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are some good introduction tutorials here;

https://spring.io/guides/gs/rest-service/

This is more spring boot, which is just a framework built on top of spring.  It takes an augmented approach offering default configurations for many services / utilities which are typically used.

Not sure what you mean by "pure REST", as I don't think there is any standard for REST web services (which is actually quite good).  Spring just extends Spring-MVC to offer REST services.    
 
Igor Janicki
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Peter Rooke: Thanks.

Now I think how to perform tests with JUnit.

I would add some @tests using Apache HTTP client.
However how to start automatically the local server with @Controller ?

I use Eclipse and Maven.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the following page: https://spring.io/guides/gs/testing-web/.
 
author
Posts: 422
13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

For what it's worth, I write a simple (non-server) controller test as early as chapter 1 in Spring in Action 5. And then, later in chapter 11, I show how to write a test that fires up a server. In that case, it is in the context of WebFlux, but the same thing would work even for testing Spring MVC.

Igor Janicki wrote:@Peter Rooke: Thanks.

Now I think how to perform tests with JUnit.

I would add some @tests using Apache HTTP client.
However how to start automatically the local server with @Controller ?

I use Eclipse and Maven.

 
Igor Janicki
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to use Rest Assured

I've got:
java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
       at io.restassured.config.EncoderConfig.<init>(EncoderConfig.java:61)
       at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
       at io.restassured.RestAssured.<clinit>(RestAssured.java:420)



POM dependencies

   <dependencies>
       <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>4.8.2</version>
           <scope>test</scope>
       </dependency>

       <dependency>
           <groupId>org.jboss.resteasy</groupId>
           <artifactId>resteasy-jaxrs</artifactId>
           <version>2.2.1.GA</version>
       </dependency>

       <dependency>
           <groupId>org.jboss.resteasy</groupId>
           <artifactId>resteasy-jackson-provider</artifactId>
           <version>2.2.1.GA</version>
       </dependency>
       
       <dependency>
           <groupId>io.rest-assured</groupId>
           <artifactId>rest-assured</artifactId>
           <version>3.0.3</version>
       </dependency>

       <dependency>
           <groupId>org.glassfish.jersey.media</groupId>
           <artifactId>jersey-media-moxy</artifactId>
           <version>2.13</version>          
       </dependency>

   </dependencies>



Any idea ?
I will appreciate even a hint.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That has already been fixed: https://github.com/rest-assured/rest-assured/commit/185f7c328873be7ef7c1afacb758031e495bd586. You need to use rest-assured 3.1.0 or higher to get that commit though.
 
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you still looking for a simple working example of spring rest application, have a look at my travelBlog I once maded for school.
It does use springboot though...
 
reply
    Bookmark Topic Watch Topic
  • New Topic