पर कोई डिफ़ॉल्ट कन्स्ट्रक्टर नहीं मिला मुझे आश्चर्य है कि फ़ील्ड इंजेक्शन @SpringBootApplication
कक्षा में क्यों काम करता है और कन्स्ट्रक्टर इंजेक्शन नहीं करता है।स्प्रिंग बूट @SpringBootAplication वर्ग
मेरे 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