Reputation: 28
I tried to create a email util and it needs some server properties. So I'd like to create a package and let application use it. If applications specify properties for email util, it should work fine. If applications don't, it should work fine as well by using default properties in email util. That means applications don't need to specify email properties for that util.
Is it possible to do that with spring annotation @Value since applications are spring mvc or spring family? Or what is the best practice for it?
Example: Application:A , EmailUtils:E, Properties:P
ps: I would like not to hardcode properties in util and then overwrite it, even pass them to constructor.
Upvotes: 1
Views: 36
Reputation: 7968
Just default it on the value annotation in EmailUtils
@Value("${some.key:my default value}")
private String stringWithDefaultValue;
Upvotes: 1