Quantcast
Channel: SpringBoot application doesn't autowire field - Stack Overflow
Viewing all articles
Browse latest Browse all 7

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

$
0
0

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 all articles
Browse latest Browse all 7

Trending Articles