I'm using @Value annotation to inject properties and now the properties have increased and the constructor is getting really big .Is there a way to handle this problem
@Component
public class Job {
private String someProperty
@Autowired
public Job(@Value("${some.property}") String someProperty,.............){
this.someProperty = someProperty
}
Just annotate the fields directly.
@Value("${some.property}")
private String someProperty
You can do any additional processing in a @PostConstruct
method.
Why dont you just do this:
@Component public class Job {
@Value("${some.property1}") private String someProperty1
@Value("${some.property2}") private String someProperty2
//...
@Autowired public Job( ){
// your someProperty1 is already set
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.