gpt4 book ai didi

java - java.lang.IllegalArgumentException:找到了多个参数类型候选:[java.lang.String]和[java.lang.Long]

转载 作者:行者123 更新时间:2023-12-02 03:33:25 30 4
gpt4 key购买 nike

我最初将findByNameAndId(String name)放入我的GetAccountsDAO中。后来,需求发生了变化,我不得不在其中添加id(Long)。

添加实现后,当我想对其进行测试时。它开始失败。

/**
* The interface that is used to get account
*/
public interface GetAccountsDAO {
@SuppressWarnings("unchecked")
public List<Account> findByNameAndId(String name, Long id);
}


错误日志为:

java.lang.IllegalArgumentException: Found more than one parameter type candidate: [java.lang.String] and [java.lang.Long]
at org.springframework.util.Assert.isNull(Assert.java:89)
at org.springframework.integration.util.MessagingMethodInvokerHelper$HandlerMethod.setExclusiveTargetParameterType(MessagingMethodInvokerHelper.java:624)
... ...

...ramework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1838ccb8] to prepare test instance [com.project.integration.account.GetAccountMockTest@6c2ed0cd]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
... ...

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#0': Cannot create inner bean 'org.springframework.integration.config.ServiceActivatorFactoryBean#6ff29830' of type [org.springframework.integration.config.ServiceActivatorFactoryBean] while setting bean property 'handlers' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ServiceActivatorFactoryBean#6ff29830': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Target object of type [class com.project.dao.account.GetAccountsDAO$$EnhancerByMockitoWithCGLIB$$83f498fd] has no eligible methods for handling Messages.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:282)
... ...

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ServiceActivatorFactoryBean#6ff29830': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Target object of type [class com.project.dao.account.GetAccountsDAO$$EnhancerByMockitoWithCGLIB$$83f498fd] has no eligible methods for handling Messages.
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:109)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:275)
... 49 more
... ...

Caused by: java.lang.IllegalArgumentException: Target object of type [class com.project.dao.account.GetAccountsDAO$$EnhancerByMockitoWithCGLIB$$83f498fd] has no eligible methods for handling Messages.
at org.springframework.util.Assert.notEmpty(Assert.java:294)
at org.springframework.integration.util.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:352)

最佳答案

您必须阅读更多documentation


  在第二种情况下(或在第一种情况下,当参数foo的参数为Map时),框架无法确定哪个参数应为payload;映射将失败。通常可以使用payload-expression@Payload批注和/或@Headers批注解决此问题。


由于您的两个String name, Long id均为原始类型,因此无法明确确定哪个类型适用于payload,因此框架会抛出该Found more than one parameter type candidate异常。

关于java - java.lang.IllegalArgumentException:找到了多个参数类型候选:[java.lang.String]和[java.lang.Long],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37751685/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com