08-02-2023, 06:59 AM
I'm using the `@Autowired` annotation under a `@Configuration` class constructor.
@Configuration
public class MyConfiguration {
private MyServiceA myServiceA;
private MyServiceB myServiceB
@Autowired
public MyConfiguration(MyServiceA myServiceA, MyServiceB myServiceB){
this.myServiceA = myServiceA;
this.myServiceB = myServiceB;
}
}
As the [Spring documentation sais][1], I'm able to declare whether the annotated dependency is required.
If I mark the `@Autowired` annotation under the constructor as `required=false`, I'm saying that the two services to be autowired are not required *(as the Spring documentation says)*:
@Autowired(required = false)
public MyConfiguration(MyServiceA myServiceA, MyServiceB myServiceB){
this.myServiceA = myServiceA;
this.myServiceB = myServiceB;
}
From Spring documentation:
> In the case of multiple argument methods, the 'required' parameter is
> applicable for all arguments.
How can I set the `required` attribute to each constructor parameter individually? Is necessary to use `@Autowired` annotation under every field?
Regards,
[1]:
@Configuration
public class MyConfiguration {
private MyServiceA myServiceA;
private MyServiceB myServiceB
@Autowired
public MyConfiguration(MyServiceA myServiceA, MyServiceB myServiceB){
this.myServiceA = myServiceA;
this.myServiceB = myServiceB;
}
}
As the [Spring documentation sais][1], I'm able to declare whether the annotated dependency is required.
If I mark the `@Autowired` annotation under the constructor as `required=false`, I'm saying that the two services to be autowired are not required *(as the Spring documentation says)*:
@Autowired(required = false)
public MyConfiguration(MyServiceA myServiceA, MyServiceB myServiceB){
this.myServiceA = myServiceA;
this.myServiceB = myServiceB;
}
From Spring documentation:
> In the case of multiple argument methods, the 'required' parameter is
> applicable for all arguments.
How can I set the `required` attribute to each constructor parameter individually? Is necessary to use `@Autowired` annotation under every field?
Regards,
[1]:
[To see links please register here]
--