Reference
- Spring Microservices in Action, Manning, 2017 Jun, https://www.manning.com/books/spring-microservices-in-action
- Getting Started · Building a RESTful Web Service, https://spring.io/guides/gs/rest-service/
Environment
- Maven: 3.5.2
- JDK: 1.8.0_131, vendor: Oracle Corporation
- OS: "windows 10"
- IDE Spring Tool Suite 3.9.4.RELEASE
1. Create the Maven project
https://start.spring.io/
- Maven project with Java and Spring Boot:
1.5.13 (failure to start)1.5.10 - Group: com.wonderland.api
- Artifact: helloworld-service
- Dependencies:
- Actuator #for the metric later
- Web
- Rest Repositories
- Eureka Discovery #for the API registration and discover later
Download: helloworld-api.zip
Unzip into {project folder}
Import into IDE: File > Import > Existing Maven Projects > {project folder} > Finish
2. Change the Code
2.1. Add class Greeting with attribute name #force the JSON response with Object return2.2. Add class HelloworldController with @RestController
2.2.1. Add method:
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name)
2.3. Update class HelloworldApiApplication with @EnableEurekaClient
3. Configure the Spring Boot application
Edit application.yml (rename the application.properties into application.yml)spring:
application:
name: helloworld-api
server:
port: 10010
logging:
level:
com.wonderland.api.helloworldapi: DEBUG
management:
security:
enabled: false
eureka:
instance:
leaseRenewalIntervalInSeconds: 5
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://localhost:30100/eureka/
4. Test the API
#> {project folder}\mvn spring-boot:runhttp://localhost:10010/hello
http://localhost:10010/hello?name=julian
4.1. Expected error about Eureka registration #to be resolved

Comments