public class DestructiveBeanWithInterface implements InitializingBean,
DisposableBean {
private InputStream is = null;
public String filePath = null;
public void afterPropertiesSet() throws Exception {
System.out.println("Initializing Bean");
if (filePath == null) { throw new IllegalArgumentException(
"You must specify the filePath property of " + DestructiveBean.class);
}
is = new FileInputStream(filePath);
}
public void destroy() {
System.out.println("Destroying Bean");
if (is != null) { try {
is.close();
is = null;
} catch (IOException ex) {
System.err.println("WARN: An IOException occured"
+ " trying to close the InputStream");
}
}
}
public void setFilePath(String filePath) { this.filePath = filePath;
}
}
public class DestructiveBean implements InitializingBean {
private InputStream is = null;
public String filePath = null;
public void afterPropertiesSet() throws Exception {
System.out.println("Initializing Bean");
if (filePath == null) { throw new IllegalArgumentException(
"You must specify the filePath property of " + DestructiveBean.class);
}
is = new FileInputStream(filePath);
}
public void destroy() {
System.out.println("Destroying Bean");
if (is != null) { try {
is.close();
is = null;
} catch (IOException ex) {
System.err.println("WARN: An IOException occured"
+ " trying to close the InputStream");
}
}
}
public void setFilePath(String filePath) { this.filePath = filePath;
}
}