Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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.
 
Rancher
Posts: 992
9
Java Linux Spring
  • 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: 21558
100
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: 21558
100
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: 933
17
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...
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!