我有这样的类和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)
我想你已经激活了@ComponentScan
,它会扫描你的@Service
注释XCalculationService
类。
所以你应该从@Service
中删除XCalculationService
或删除
@Bean
public XCalculationService calculationService() {
return new XCalculationService ();
}
来自ServiceConfiguration