This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

simple REST with Spring example  RSS feed

 
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
  • 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: 1008
18
IntelliJ IDE Java Linux Mac OS X Oracle Redhat Spring Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 12
Eclipse IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
  • 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: 21638
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the following page: https://spring.io/guides/gs/testing-web/.
 
author
Posts: 396
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 12
Eclipse IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
  • 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: 21638
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!