配置:
@Configuration
public class CoreConfig {
@Bean
public StatusService statusService(StatusPersistenceService statusPersistenceService) {
return new StatusEventHandler(statusPersistenceService);
}
}
Spring 类抱怨没有默认构造函数
@Configuration
public class StatusEventHandler implements StatusService {
private final StatusPersistenceService statusPersistenceService;
@Autowired
public StatusEventHandler(final StatusPersistenceService statusPersistenceService) {
this.statusPersistenceService = statusPersistenceService;
}
}
注入此 bean 的控制器:
@Controller
@RequestMapping("/showStatus")
public class ShowStatusController {
@Autowired
private StatusService statusService;
}
这会编译并且测试通过,但是当发布到应用服务器时,我收到以下错误。为什么 Spring 认为应该有一个默认的无参数构造函数?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'statusEventHandler'
...
No default constructor found;