The below implementation works well for me. You have two issues, first you have to choose between @Service and @Bean and the other issue I've seen in your code was the @Value annotation, you have to use only to inject a value from the properties.
@SpringBootApplication
public class TestedValueApplication {
@Autowired
void printServiceInstance(ServiceA service) {
System.out.println("Service instance: " + service);
System.out.println("value==value? " + service.isFieldA("value"));
}
public static void main(String[] args) {
SpringApplication.run(TestedValueApplication.class, args);
}
@Bean
public ServiceA serviceA(@Value("${fieldA}") String fieldA) {
return new ServiceAImpl(fieldA);
}
}
Service:
public class ServiceAImpl implements ServiceA {
private String fieldA;
ServiceAImpl(String fieldA) {
this.fieldA = fieldA;
}
public boolean isFieldA(String text) {
return fieldA.equals(text);
}
}
application.properties:
fieldA=value