フィールド注入が@SpringBootApplication
クラスで動作し、コンストラクタインジェクションがなぜ動作しないのだろうと思います。スプリングブート@SpringBootApplicationクラスにデフォルトコンストラクタが見つかりません
マイApplicationTypeBean
で期待どおりに動作しますが、私はCustomTypeService
のコンストラクタ・インジェクションを持つようにしたいとき、私はこの例外を受け取る:
Failed to instantiate [at.eurotours.ThirdPartyGlobalAndCustomTypesApplication$$EnhancerBySpringCGLIB$$2a56ce70]: No default constructor found; nested exception is java.lang.NoSuchMethodException: at.eurotours.ThirdPartyGlobalAndCustomTypesApplication$$EnhancerBySpringCGLIB$$2a56ce70.<init>()
それは@SpringBootApplication
クラスでは動作しない理由何らかの理由はありますか?
マイSpringBootApplicationクラス:
@SpringBootApplication
public class ThirdPartyGlobalAndCustomTypesApplication implements CommandLineRunner{
@Autowired
ApplicationTypeBean applicationTypeBean;
private final CustomTypeService customTypeService;
@Autowired
public ThirdPartyGlobalAndCustomTypesApplication(CustomTypeService customTypeService) {
this.customTypeService = customTypeService;
}
@Override
public void run(String... args) throws Exception {
System.out.println(applicationTypeBean.getType());
customTypeService.process();
}
public static void main(String[] args) {
SpringApplication.run(ThirdPartyGlobalAndCustomTypesApplication.class, args);
}
public CustomTypeService getCustomTypeService() {
return customTypeService;
}
マイ@Serviceクラス:
@Service
public class CustomTypeService {
public void process(){
System.out.println("CustomType");
}
}
マイ@Componentクラス:
@Component
@ConfigurationProperties("application.type")
public class ApplicationTypeBean {
private String type;
ご理解いただきありがとうございます。 – Patrick
引用符が鍵です。私は4.3からダウングレードする必要がありました。これはどこで実行可能です。 – sschrass