How to create springboot app:
1.Using spring cli
2. https://start.spring.io/
3.Maven and dependencys
RestTemplate resttemplate = new RestTemplate();
resttemplate.getForObject(Stirng Url, Object out put Class);
Creating Bean in Spring boot
In Main method of spring
@SpringBootApplication
public Main class{
@Bean
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
public void main method{
}
}
in Controller
@Autowired
RestTemplate reasttemplate;
resttemplate.getForObject()
Webclient vs Resttemplate
Webclint: Async requests
Resttemplate: sync request
to handle web urls we have service discovery concept
client <----> service discovery <-----> service 1, service 2, service 3
download euraka server from start.spring.io.
and put dependency as Euraka Server
need to add below dependency for client and version
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
and in properties add
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
and add applicatoin name in application.properties.
spring.application.name=testapp
1.Using spring cli
2. https://start.spring.io/
3.Maven and dependencys
RestTemplate resttemplate = new RestTemplate();
resttemplate.getForObject(Stirng Url, Object out put Class);
Creating Bean in Spring boot
In Main method of spring
@SpringBootApplication
public Main class{
@Bean
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
public void main method{
}
}
in Controller
@Autowired
RestTemplate reasttemplate;
resttemplate.getForObject()
Webclient vs Resttemplate
Webclint: Async requests
Resttemplate: sync request
to handle web urls we have service discovery concept
client <----> service discovery <-----> service 1, service 2, service 3
download euraka server from start.spring.io.
and put dependency as Euraka Server
need to add below dependency for client and version
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
and in properties add
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
and add applicatoin name in application.properties.
spring.application.name=testapp
how to to discover the servec url
on @RestTemplate use @LoadBalanced keyword and in the resttemplate url use application.name value to discover
Example
service application name->RBAC-SERVICE
resttemplate.getForObject("http://RBAC-SERVICE/getpermissions")