Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring integration Spring集成Jpa |在JavaDSL中插入带有Jpa的行_Spring Integration_Spring Integration Dsl - Fatal编程技术网

Spring integration Spring集成Jpa |在JavaDSL中插入带有Jpa的行

Spring integration Spring集成Jpa |在JavaDSL中插入带有Jpa的行,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我在互联网上搜索了不少信息,但无法获得以下信息: 插入带有JpaUpdatingOutboundEndpointSpec的行的具体示例 @Bean public JpaUpdatingOutboundEndpointSpec insertToTable() { return Jpa.updatingGateway(entityManger) .entityClass(EntitySample.class); } 以上就够了吗 请帮帮我 没错,在某些情况下,

我在互联网上搜索了不少信息,但无法获得以下信息:

插入带有
JpaUpdatingOutboundEndpointSpec
的行的具体示例

@Bean
public JpaUpdatingOutboundEndpointSpec insertToTable() {
    return Jpa.updatingGateway(entityManger)
              .entityClass(EntitySample.class); 
}
以上就够了吗


请帮帮我

没错,在某些情况下,这些代码可能已经足够了。从这里了解如何使用此代码将是一件非常棒的事情。尽管同时我将与您分享我的测试配置和测试本身:

    @Bean
    public IntegrationFlow outboundAdapterFlow(EntityManagerFactory entityManagerFactory) {
        return f -> f
                .handle(Jpa.outboundAdapter(entityManagerFactory)
                                .entityClass(StudentDomain.class)
                                .persistMode(PersistMode.PERSIST),
                        e -> e.transactional(true));
    }

@Autowired
@限定符(“outboundAdapterFlow.input”)
私有消息通道外部适配器流量输入;
@试验
public void testOutboundAdapterFlow(){
JdbcTemplate JdbcTemplate=新的JdbcTemplate(数据源);
List results1=jdbcTemplate.queryForList(“从学生中选择*);
assertNotNull(结果1);
assertTrue(results1.size()=3);
Calendar dateOfBirth=Calendar.getInstance();
出生日期(1981年9月27日);
StudentDomain student=新建StudentDomain()
.使用名字(“Artem”)
.withLastName(“Bilan”)
.有性别(性别.男性)
.withDateOfBirth(dateOfBirth.getTime())
.withLastUpdated(新日期());
assertNull(student.getRollNumber());
this.outboundAdapterFlowInput.send(MessageBuilder.withPayload(student.build());
List results2=jdbcTemplate.queryForList(“从学生中选择*);
assertNotNull(结果2);
assertTrue(results2.size()=4);
assertNotNull(student.getRollNumber());
}

您可以在框架的测试类中找到更多关于Spring Integration Java DSL for JPA的测试:

谢谢您的快速回复!所以这就像FTPOutboundAdapter接受成功和异常的建议一样,对吗?是的,这是正确的。您也可以在JPA的
.handle()
中使用
表达式evaluationRequestHandlerAdvice
@Autowired
@Qualifier("outboundAdapterFlow.input")
private MessageChannel outboundAdapterFlowInput;

@Test
public void testOutboundAdapterFlow() {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    List<?> results1 = jdbcTemplate.queryForList("Select * from Student");
    assertNotNull(results1);
    assertTrue(results1.size() == 3);

    Calendar dateOfBirth = Calendar.getInstance();
    dateOfBirth.set(1981, 9, 27);

    StudentDomain student = new StudentDomain()
            .withFirstName("Artem")
            .withLastName("Bilan")
            .withGender(Gender.MALE)
            .withDateOfBirth(dateOfBirth.getTime())
            .withLastUpdated(new Date());

    assertNull(student.getRollNumber());

    this.outboundAdapterFlowInput.send(MessageBuilder.withPayload(student).build());

    List<?> results2 = jdbcTemplate.queryForList("Select * from Student");
    assertNotNull(results2);
    assertTrue(results2.size() == 4);

    assertNotNull(student.getRollNumber());
}