Spring 集成服务激活器引用 Hibernate JPA 存储库方法

Spring Integration service-activator referencing Hibernate JPA repository method

我正在尝试使用 Hibernate JPA 存储库方法作为服务激活器的方法。链中的定义如下所示。

<int:chain input-channel="bootstrapLineupCdsStart" output-channel="bootstrapLineupItemCdsStart">
    <int:service-activator ref="lineupRepository" method="findByIntegrationStatusNew" />
    <int:filter expression="!payload.isEmpty()" discard-channel="bootstrapLineupItemCdsStart"/>
    <int:splitter expression="payload"/>
    <int:service-activator ref="lineupServicePipeline" method="createLineup"/>
    <int:aggregator/>
</int:chain>

违规行是第一个服务激活器,特别是这一行<int:service-activator ref="lineupRepository" method="findByIntegrationStatusNew" />

为了完整起见,这里是存储库 class 本身

@Repository( "lineupRepository" )
public interface LineupRepository extends JpaRepository<LineupEntity, Integer> {
    @Query("select l from LineupEntity l where l.integrationStatus = 0")
    List<LineupEntity> findByIntegrationStatusNew();
}

现在由于 spring/hibernate 的魔力,我实际上并没有自己实现 findByIntegrationStatusNew;这是由框架在运行时动态实现的。我也不需要显式定义 lineupRepository bean,因为 @Repository 注释会为我处理这个。

由于上述原因,我得到了以下异常。

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#9$child#0.handler': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Target object of type [class com.sun.proxy.$Proxy79] has no eligible methods for handling Messages.

最后,我确实有一个似乎可以完成工作的变通方法;这是一个明显的解决方法,我怀疑没有必要。解决方法包括创建一个新 bean,在上下文 XML 中显式定义 bean 并调用该方法而不是存储库中的方法。所以我的工作看起来有点像这样;首先,解决方法的上下文看起来像这样。

<int:chain input-channel="bootstrapLineupCdsStart" output-channel="bootstrapLineupItemCdsStart">
    <int:service-activator ref="lineupRepositoryService" method="findByIntegrationStatusNew" />
    <int:filter expression="!payload.isEmpty()" discard-channel="bootstrapLineupItemCdsStart"/>
    <int:splitter expression="payload"/>
    <int:service-activator ref="lineupServicePipeline" method="createLineup"/>
    <int:aggregator/>
</int:chain>
<bean id="lineupRepositoryService" class="com.mypackage.LineupRepositoryService"/>

注意第一个服务激活器现在引用 LineupRepositoryService 而不是 LineupRepository,我还添加了一个新的 bean 定义。

其次,当然,我还定义了一个 LineupRespositoryService class,如下所示。

public class LineupRepositoryService {
    @Autowired
    private LineupRepository lineupRepository;

    public List<LineupEntity> findByIntegrationStatusNew() {
        return lineupRepository.findByIntegrationStatusNew();
    }
}

解决方法有效,但我宁愿以正确的方式进行。所以有人知道我如何让它正常工作或这里发生了什么吗?

@JeffreyPhillipsFreeman,我们通过测试用例确认这是Spring集成反射方法调用角度的问题。

无论如何都需要修复它:https://jira.spring.io/browse/INT-3820

也就是说,只有像您的 service wrapper.

这样的解决方法