Eureka working :)

http://localhost:8100/currency-converter-feign/from/EUR/to/INR/quantity/2000

{"id":10002,"from":"EUR","to":"INR","conversionMultiple":75.00,"quantity":2000,"totalCalculatedAmount":150000.00,"port":8001}

 

Both services registered with Eureka:

Instances currently registered with Eureka

Application AMIs Availability Zones Status
CURRENCY-CONVERSION-SERVICE n/a (1) (1) UP (1) – gandalf.lan:currency-conversion-service:8100
CURRENCY-EXCHANGE-SERVICE n/a (2) (2) UP (2) – gandalf.lan:currency-exchange-service:8000 , gandalf.lan:currency-exchange-service:8001

 

Finally it all works, but got one error:

2018-10-10 10:15:56.797 ERROR 1524 — [et_localhost-13] c.n.e.cluster.ReplicationTaskProcessor : It seems to be a socket read timeout exception, it will retry later. if it continues to happen and some eureka node occupied all the cpu time, you should set property ‘eureka.server.peer-node-read-timeout-ms’ to a bigger value

Not too worried, going on to Zuul API Gateway now.

Using Feign… errors and success

In the tutorial (Step 21) we need to use Feign. He suggested a pom.xml dependency, but the import didn’t match up.

He was importing:

import org.springframework.cloud.netflix.feign.EnableFeignClients;

and

import org.springframework.cloud.netflix.feign.FeignClient;

But there was nothing in the dependency he advocated. After a bit of searching:

Change:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>

to:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>

But this gave all sorts of weird errors, like:

FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class

and:

JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface [util.c:1313]

After removing all the Feign stuff, it was still not right, so I removed the netflix dependency and it was fine.

After a bit of searching I found that  spring-cloud-starter-feign was deprecated and I had to use spring-cloud-starter-openfeign.

A clean, stop and start, and we’re away again, phew! 

Error connecting to http://localhost:8888/limits-service/default with spring.cloud.config.server.git.uri property

I’m following the Microservices tutorial and have come across an error when trying to get properties from my git repository. It’s an easy one, just change the back-slash to forward slashes 🙂

In application.properties:

spring.cloud.config.server.git.uri=file://C:/Users/Me/git/spring-micro-services/git-localconfig-repo

Disabling Spring Boot Security for h2 console

In application.properties:

spring.h2.console.enabled=true
spring.h2.console.path=/h2console/

In my security configuration class I added a bit more to the HttpSecurity configuration:

package com.example.demo;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception{

http.authorizeRequests().antMatchers("/").permitAll().and()
.authorizeRequests().antMatchers("/h2console/**").permitAll();
http.csrf().disable();
http.headers().frameOptions().disable();


}
}

Enabling Spring Boot Security – then disabling it

I added spring-boot-starter-security to my pom, but I’m trying to access the h2-console on localhost and it’s failing because I need to log in.

In my application.xml I have:

spring.security.user.name=user
spring.security.user.password=password

But I don’t want to type this in. How do I disable it? I created a new class in the root of my project and it seemed to work.

package com.example.demo;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests().antMatchers("/").permitAll();
}
}

 

 

devtools not working

I used it before, everything was fine, but it seems that in running my application as a Java Project and not a Spring Boot Application from STS, it did not force a restart of the server.

I found this:

https://stackoverflow.com/questions/49386434/live-reload-not-working-in-spring-boot-devtools

“Developer tools are automatically disabled when running a fully packaged application.
If your application is launched from java -jar, you don’t use the spring-boot maven plugin to run your application.”

management.security.enabled=false not working

I’m, following a tutorial on Safari (Master Microservices with Spring Boot and Spring Cloud ; Learn the fundamentals of Microservices to create fault tolerant Microservices
Ranga Karanam) and in the Spring Boot appendix he uses the actuator.

Obviously things have changed. The old way doesn’t work as it’s been deprecated:

management.security.enabled=false

So I used:

management.endpoints.web.exposure.include=*

Maven dependencies for the tutorial included:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
</dependency>

The username was user and the password was generated on the console output during startup.

http://localhost:8080/browser/index.html#http://localhost:8080/actuator

Gave me what I was looking for.

http://localhost:8080/browser/index.html#http://localhost:8080/book

Gave me my book data in JSON that was hard-coded into the @GetMapping for /book in my BooksController @RestController.

Actuators

Can’t follow the Safari Spring Boot tutorial again as it is out of date, but found this lovely article:

https://www.baeldung.com/spring-boot-actuators

It describes the changes per version. Everything is under /actuator now, and we only get health and info by default.

BUT – make sure you download the spring-boot-starter-actuator, and not the spring-boot-actuator, or you’ll get nothing!