Quantcast
Viewing latest article 7
Browse Latest Browse All 7

SpringBoot application doesn't autowire field


I do have ServiceImpl which looks like this:

@Service
@RequiredArgsConstructor
public class ServiceAImpl implements ServiceA {
private final String fieldA;
@Override 
public boolean isFieldA(String text){
return fieldA.equals(text);
}

And I would like to inject a field value to fieldA in an Application.java from application.yml like this:

@EnableSwagger2
@SpringBootApplication
public class Application {
@Value("${fieldA}")
private String fieldA;
public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}
@Bean
public ServiceA serviceA() {
    return new ServiceAImpl(fieldA);
}

But I receive the following error when running SpringBoot app:

Error creating bean with name 'serviceAImpl' defined in URLNo qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Do you have any solution for that?


Viewing latest article 7
Browse Latest Browse All 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>