I am doing POC on Spring Boot + Spring Data Redis by taking reference from https://www.youtube.com/watch?v=_M8xoagybzU&t=231s and simply following the tutorial using Spring Boot version 2.1.0.RELEASE
instead of 2.0.0.RELEASE
.
I am simply updating the Redis cache into DB and getting the below error.
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method repositories in com.example.RedisApplication required a bean of type 'com.example.RedisApplication$LineItemRepository' that could not be found.
Action:
Consider defining a bean of type 'com.example.RedisApplication$LineItemRepository' in your configuration.
RedisApplication.java
@Log
@SpringBootApplication
public class RedisApplication {
private ApplicationRunner titleRunner(String title, ApplicationRunner rr) {
return args -> {
log.info(title.toUpperCase() + ":");
rr.run(args);
};
}
@Bean
ApplicationRunner geography(RedisTemplate<String, String> rt) {
return titleRunner("geography", args -> {
GeoOperations<String, String> geo = rt.opsForGeo();
geo.add("Sicily", new Point(13.361389, 38.155556), "Arigento");
geo.add("Sicily", new Point(15.087269, 37.502669), "Catania");
geo.add("Sicily", new Point(13.583333, 37.316667), "Palermo");
Circle circle = new Circle(new Point(13.583333, 37.316667),
new Distance(100, RedisGeoCommands.DistanceUnit.KILOMETERS));
GeoResults<GeoLocation<String>> radius = geo.radius("Sicily", circle);
radius.getContent().forEach(c -> log.info(c.toString()));
});
}
@Bean
ApplicationRunner repositories(LineItemRepository lineItemRepository) {
return titleRunner("repositories", args -> {
Long orderId = generateId();
List<LineItem> itemsList = Arrays.asList(
new LineItem(orderId, generateId(), "plunger"),
new LineItem(orderId, generateId(), "soup"),
new LineItem(orderId, generateId(), "cofee mug"));
itemsList.stream().map( lineItemRepository::save).forEach(li -> log.info(li.toString()));
});
}
private Long generateId() {
long tmp = new Random().nextLong();
return Math.max(tmp, tmp * -1);
}
public static void main(String[] args) {
SpringApplication.run(RedisApplication.class, args);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("orders")
public class Order implements Serializable {
@Id
private Long Id;
@Indexed
private Date when;
@Reference
private List<LineItem> lineItems;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("lineItems")
public class LineItem implements Serializable {
@Indexed
private Long orderId;
@Id
private Long id;
private String description;
}
interface LineItemRepository extends CrudRepository<LineItem, Long> {
}
interface OrderRepository extends CrudRepository<Order, Long> {
Collection<Order> findByWhen(Date date);
}
}