Spring Boot RestController Error: “No converter found for return value of type”

Spring Boot RestControllers by default can return a Pojo class as the return result from a mapped request method, and it is converted into a Json result. I’ve run into this issue before though, and it’s not immediately obvious what’s wrong: ‘No converter found for return value of type’ :

java.lang.IllegalArgumentException: No converter found for return value 
of type: class kh.springboot.redis.domain.RedisResult
at org.springframework.web.servlet.mvc.method.annotation
.AbstractMessageConverterMethodProcessor
.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:187) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]

My returned class from my @GetMapping method is just a simple Pojo:

public class RedisResult {

private String key;
private String value;

public RedisResult(String key, String value) {
  this.key = key;
  this.value = value;
  }
}

And my @RestController is a simple controller with a single @GetMapping (in this case I’m building a REST endpoint to query key values from Redis using Spring Data Redis RedisTemplate:

@RestController

public class RedisRestController {

  @Autowired
  @Qualifier("RedisTemplate")
  private RedisTemplate template;

  @GetMapping("singlekey/{key}")
  public RedisResult getSingleValue(@PathVariable("key") String key){
    String value = (String)this.template.opsForValue().get(key);
    RedisResult result = new RedisResult(key, value);
    return result;
  }
}

If you’ve found my post because you have this same issue, before you go down the rabbit hole adding additional Maven dependencies or additional annotations you think might be missing, the reason is usually that your Pojo class you are returning doesn’t have any public getter methods. For each property in your Pojo you want returned in your Json, make sure you have a public getter.

This is discussed in this StackOverflow post here.

Redis: getting started and basics

Redis is a key/value in-memory datastore. The Getting Started guide will get you up and running pretty quick.

Startup:

./redis-server

CLI:

./redis-cli

From cli, inserting a value:

set key value

Get a value:

get key

List keys:

keys pattern

List all keys, not recommended against a large prod database:

keys *

Spring Boot: cannot find classfile ConfigurableApplicationContext (invalid LOC header)

Spring Boot with it’s maven starter dependencies is incredibly helpful to get a simple Spring Boot app up and running in no time, but occasionally you run into weird errors in Eclipse like:

The project was not built since its build path is incomplete. 
Cannot find the class file for 
org.springframework.context.ConfigurableApplicationContext. 
Fix the build path then try building this project

Or doing a mvn compile from your shell, something like:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] error reading /Users/kev/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.11/tomcat-embed-core-8.5.11.jar; invalid LOC header (bad signature)

Assuming you’re already using the Spring Boot Starter Web dependency:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

.. errors about Classes not found or errors reading .jars (‘invalid LOC header’) could be related to jars in your local .m2 repo being corrupt.

This is pretty easy to correct if you go into your ~/.m2/repository/ and delete your downloaded dependencies. You can be more specific in what you delete if you have something that you can easily identify as coming from a specific dependency.

Digital Research – Pacific Grove, California

Gary Kildall and his company Digital Research played a pivotal part in the history of the development of the IBM PC. IBM approached Bill Gates and Paul Allen to provide a number of programming languages for the original IBM PC, and later returned to Microsoft to ask if they could also provide the operating system. Not having anything available at the time, Gates suggested they talk with Gary Kildall at Digital Research, who had developed the CP/M operating system for 8080 based computers at the time.

The history of exactly what happened during the meeting with IBM and Gary’s wife at Digital Research may never be clear, but for whatever reason, Kildall was unavailable to discuss with IBM. When IBM returned to Gates and Allen, they decided to go talk with Rod Brock and Tim Patterson at Seattle Computer Products (SCP) and licensed their QDOS operating system for the 8086 for $10,000 and $15,000 for each company that licensed the product from Microsoft. This became the basis for MS-DOS, The rest, is history.

(If you’re interested, I highly recommend the book Fire in the Valley, a great book which covers the story of the IBM PC in detail, as well as earlier and later history)

The original location of Digital Research is at 801 Lighthouse Ave, in Pacific Grove, California. The building is now a private residence. On a vacation to Pacific Grove earlier this month, I looked up the location where the office was, and as it was only a couple of blocks from where we were staying, so we stopped by:

 

 

 

This IEEE have installed a plaque on the sidewalk outside the building to commemorate the contributions of Gary Kildall, Digital Research and the CP/M operating system: