Spring Code Design
1. Is it good to Inject @Value variables in abstract class ?
@Value variables in abstract class ?When it works ?
public abstract class BaseHandler {
@Value("${app.timeout}")
protected int timeout;
}@Component
public class MyHandler extends BaseHandler {
// You can use 'timeout' here
}Why it’s generally discouraged ?
Recommended Alternative
2. Can controller method add/modify/remove validation annotations that are not present in the original interface ?
Solutions
Option 1: Add the same constraint to the OpenAPI interface
Option 2: Do not add constraints in the implementing method
Last updated