1

I see many examples related to spring-integration-file. But I am looking for an example application where it uses spring-integration-jpa to pull data from database using Inbound Channel Adapter and create a Java object out of it.

Any help is much appreciated.

Vicky
  • 11
  • 2

1 Answers1

2

There is a basic JPA sample in the official Spring Integration Samples repository: https://github.com/spring-projects/spring-integration-samples/tree/master/basic/jpa.

The simple Java DSL sample for Inbound Channel Adapter might look like this:

    @Bean
    public IntegrationFlow pollingAdapterFlow(EntityManagerFactory entityManagerFactory) {
        return IntegrationFlows
                .from(Jpa.inboundAdapter(entityManagerFactory)
                                .entityClass(StudentDomain.class)
                                .maxResults(1)
                                .expectSingleResult(true),
                        e -> e.poller(p -> p.trigger(new OnlyOnceTrigger())))
                .channel(c -> c.queue("pollingResults"))
                .get();
    }
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 1
    Why are (almost) all the examples XML-based in that repository? It's so painfull. – Ekaterina Jan 03 '20 at 14:07
  • 1
    Because they have been made those old days when only an XML configuration existed. Right now we just don't have enough resources to maintain Java DSL samples as well. – Artem Bilan Jan 03 '20 at 14:30
  • For java configurations you can see here https://docs.spring.io/spring-integration/reference/html/jpa.html#configuring-with-java-configuration – sam Sep 14 '21 at 17:27