Paramètre 0 des référentiels de méthode dans com.example.RedisApplication requis un bean de type qui ne pouvait pas être trouvé

voix
0

Je fais POC sur Spring Boot + printemps données Redis en prenant référence à partir https://www.youtube.com/watch?v=_M8xoagybzU&t=231s et simplement suivant le tutoriel en utilisant la version Spring Boot au 2.1.0.RELEASElieu de 2.0.0.RELEASE.

Je suis simplement mettre à jour le cache Redis dans DB et obtenir l'erreur ci-dessous.

***************************
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);
    }
}
Créé 07/11/2018 à 20:19
source utilisateur
Dans d'autres langues...                            


1 réponses

voix
1

J'ai pu résoudre ce problème. D'une certaine façon dépôt référence de l'ordre et LineItem n'était pas disponible. Alors je simplement déplacé le POJO et les classes du référentiel de méthode principale.

RedisApplication.java

@Log
@SpringBootApplication
public class RedisApplication {

    @Autowired
    private OrderRepository orderRepository;
    @Autowired
    private LineItemRepository lineItemRepository;

    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()));
        });
    }

    public static void main(String[] args) {
        SpringApplication.run(RedisApplication.class, args);
    }



    @Bean
    ApplicationRunner repositories() {
        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()));

            Order order = new Order(orderId, new Date(), itemsList);
            orderRepository.save(order);

            Collection<Order> found = orderRepository.findByWhen(order.getWhen());
            found.forEach(o -> log.info("found : " + o.toString()));
        });
    }

    private Long generateId() {
        long tmp = new Random().nextLong();
        return Math.max(tmp, tmp * -1);
    }
}

Voici la sortie -

2018-11-08 12:25:23.469  INFO 4380 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-08 12:25:23.473  INFO 4380 --- [           main] com.example.RedisApplication             : Started RedisApplication in 4.272 seconds (JVM running for 5.071)
2018-11-08 12:25:23.473  INFO 4380 --- [           main] com.example.RedisApplication             : GEOGRAPHY:
2018-11-08 12:25:23.497  INFO 4380 --- [           main] com.example.RedisApplication             : GeoResult [content: RedisGeoCommands.GeoLocation(name=Palermo, point=null), distance: 0.0, ]
2018-11-08 12:25:23.497  INFO 4380 --- [           main] com.example.RedisApplication             : GeoResult [content: RedisGeoCommands.GeoLocation(name=Arigento, point=null), distance: 0.0, ]
2018-11-08 12:25:23.497  INFO 4380 --- [           main] com.example.RedisApplication             : REPOSITORIES:
2018-11-08 12:25:23.581  INFO 4380 --- [           main] com.example.RedisApplication             : LineItem(orderId=3202446132704215083, id=1657375889205537882, description=plunger)
2018-11-08 12:25:23.589  INFO 4380 --- [           main] com.example.RedisApplication             : LineItem(orderId=3202446132704215083, id=5508942963105786137, description=soup)
2018-11-08 12:25:23.593  INFO 4380 --- [           main] com.example.RedisApplication             : LineItem(orderId=3202446132704215083, id=2166030250698224804, description=cofee mug)
2018-11-08 12:25:23.665  INFO 4380 --- [           main] com.example.RedisApplication             : found : Order(Id=3202446132704215083, when=Thu Nov 08 12:25:23 IST 2018, lineItems=[LineItem(orderId=3202446132704215083, id=1657375889205537882, description=plunger), LineItem(orderId=3202446132704215083, id=5508942963105786137, description=soup), LineItem(orderId=3202446132704215083, id=2166030250698224804, description=cofee mug)])
Créé 08/11/2018 à 06:58
source utilisateur

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more