Issue
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@Configuration
@ConfigurationProperties("promotion")
public class PromotionConfig {
private AppClientConfig appConfig;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AppClientConfig {
private int readTImeout;
private int writeTimeout;
}
When I am trying to do @Autowire PromotionConfig It is throwing an error that No Qualifying bean found for AppClientConfig.
I know this error is coming up because I dont have @Component in AppClientConfig.
How can i make it work without adding @Component in AppClientConfig. I want to keep it Plain POJO class.
My local.yml file
promotion:
appConfig:
readTImeout: 10
writeTimeout: 10
Solution
You can load statically the spring bean in non spring classes as:
PromotionConfig PromotionConfig = ApplicationInitializer.getAppContext().getBean(PromotionConfig.class);
Answered By - user7294900
Answer Checked By - David Goodson (JavaFixing Volunteer)