Quantcast
Viewing latest article 5
Browse Latest Browse All 7

Answer by Tom Van Rossom for SpringBoot application doesn't autowire field

Try this

@Service
public class ServiceAImpl implements ServiceA { 
    private final String fieldA;

    @Autowire
    public ServiceAImpl(@Value("${fieldA}") String fieldA){
        this.fieldA = fieldA;
    }

    @Override 
    public boolean isFieldA(String text){
        return fieldA.equals(text);
    }
}

and this

@EnableSwagger2
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

You should not use @Service and @Bean for the same class!


Viewing latest article 5
Browse Latest Browse All 7

Trending Articles



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