我正在尝试使用 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" />
为了完整起见,这里是存储库类本身
@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 ;这是由框架在运行时动态实现的。我也不需要显式定义erielineRepository 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 类,如下所示。
public class LineupRepositoryService {
@Autowired
private LineupRepository lineupRepository;
public List<LineupEntity> findByIntegrationStatusNew() {
return lineupRepository.findByIntegrationStatusNew();
}
}
解决方法有效,但我宁愿以正确的方式进行。那么有人知道我如何才能让它正常工作或者这里发生了什么?
最佳答案
@JeffreyPhillipsFreeman,我们通过测试用例确认这是 Spring Integration 反射方法调用角度的问题。
无论如何都需要修复它:https://jira.spring.io/browse/INT-3820 .
意味着虽然只有像您的服务包装器
这样的解决方法。
关于java - Spring Integration 服务激活器引用 Hibernate JPA 存储库方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32382586/