I have the following code:
public final class PropertyFileLoader {
private static final Logger logger = LoggerFactory.getLogger(PropertyFileLoader.class);
private final String propertyFileName;
public PropertyFileLoader (String propertyFileName) {
this.propertyFileName = propertyFileName;
}
public Properties getClasspathFileAsStream () {
final Properties properties = new Properties();
final InputStream is = getClass().getClassLoader().getResourceAsStream(propertyFileName);
try {
properties.load(is);
}
catch (final IOException e) {
logger.error(e.getLocalizedMessage(), e);
// throw new IOException();
}
return properties;
}
}
How do you think, should I use static
methods instead of constructor?
The usage of this class:
final PropertyFileLoader loader = new PropertyFileLoader("flyway.properties");
final Properties flywayProperties = loader.getClasspathFileAsStream();
And I think add the static
method such as
public static Properties getClasspathProperties(String propertyFileName){
final PropertyFileLoader loader = new PropertyFileLoader(propertyFileName);
return loader.getClasspathFileAsStream();`
}
Should I throw IOException, if I use classpath directory? If yes, why?
Could I use this class as Spring @Component
with @Value
?
I found how to @Autoware
constructor with param using @Value
annotation, but how to use this at another class?
is
is never closed. \$\endgroup\$