gpt4 book ai didi

java - BeanNotOfRequiredTypeException : Bean named X is expected to be of type X but was actually of type 'com. sun.proxy.$Proxy

转载 作者:搜寻专家 更新时间:2023-10-31 08:31:12 27 4
gpt4 key购买 nike

我有这样的类和 Spring 上下文。

如何修复这个错误的 Java 配置,而不是 xml?

我尝试了其他帖子中的一些解决方案,但没有成功。

@Service
@Transactional
public class XCalculationService implements VoidService<X> {
}

public interface VoidService<Input> {
}

@AllArgsConstructor
public class XService {
private XCalculationService calculationService;
}

@Configuration
public class ServiceConfiguration {
@Bean
public OrderService orderService(XCalculationService calculationService) {
return new XService(calculationService);
}

@Bean
public XCalculationService calculationService() {
return new XCalculationService ();
}
}

错误

BeanNotOfRequiredTypeException: Bean named 'calculationService' is expected to be of type 'com.x.XCalculationService' but was actually of type 'com.sun.proxy.$Proxy

最佳答案

这是 100% 修复:

@EnableTransactionManagement(proxyTargetClass = true)

关于java - BeanNotOfRequiredTypeException : Bean named X is expected to be of type X but was actually of type 'com. sun.proxy.$Proxy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52603759/

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