> > a "ds" bean... can Spring just do
> > MyServletFilter.setDataSource(myDataSourceBean) at startup?
>
Nick said:
> Unless Spring instantiates the bean, the answer is "no." You can ask
> spring to configure a bean programmatically:
I'm not so sure that's the case for static stuff.
In fact, I kind of surprised myself -- my config of my Configuration bean
already looks like it does what I'm asking about doing....sorta. :-)
I don't believe this trick will work for EventLog objects, but have a look
at this static setup magic:
<bean id="FOOappConfiguration"
class="common.Configuration"
init-method ="start">
<property name="myConfigurationFiles" >
<value>/resources/application.properties,/resources/sql.properties</value>
</property>
</bean>
Relevant bits of Configuration.java
private static String theConfigFiles = "";
private static Properties theProperties = null;
/**
* This is a utility class and is never instantiated.
*/
private Configuration() {}
/**
* Tells the class which property file(s) to read.
* @param filenames
*/
public void setMyConfigurationFiles(String filenames) {
theConfigFiles = filenames;
}
/**
* Starts up the class, reads in the config file(s).
*/
public static void start() {
// load properties
Properties props = new Properties();
InputStream in = null;
logger.info("Configuration init - " + theConfigFiles);
// allow for comma separated list of config files
StringTokenizer tokenizer = new StringTokenizer(theConfigFiles,
",");
while (tokenizer.hasMoreTokens()) {
String currentFile = tokenizer.nextToken();
logger.info("loading config file:" + currentFile);
try {
in = Configuration.class.getResourceAsStream(currentFile);
if (null != in) {
props.load(in);
logger.info(currentFile + " - loaded.");
}
else {
logger.error(currentFile + " - NOT FOUND");
}
} catch (Exception e) {
logger.error("Unable to load" + currentFile + ", the error
is: " + e);
} finally {
try {
in.close();
} catch (Exception ignored) {
}
}
}
theProperties = props;
}
------
During startup --
INFO [main] [2004-09-24 14:18:26,607]
[org.springframework.beans.factory.support.DefaultListableBeanFactory]-
Creating shared instance of singleton bean 'FOOappConfiguration'
INFO [main] [2004-09-24 14:18:26,617] [common.Configuration]- Configuration
init - /resources/application.properties,/resources/sql.properties
INFO [main] [2004-09-24 14:18:26,617] [common.Configuration]- loading
config file:/resources/application.properties
INFO [main] [2004-09-24 14:18:26,617] [common.Configuration]-
/resources/application.properties - loaded.
INFO [main] [2004-09-24 14:18:26,617] [common.Configuration]- loading
config file:/resources/sql.properties
INFO [main] [2004-09-24 14:18:26,617] [common.Configuration]-
/resources/sql.properties - loaded.
And then later when I use Configuration.getProperty("test") -> I get the
expected value.
So it seems Spring configured a Configuration class instance, byproduct is
initialized static info... so I get a config'd Configuration Utility class,
which is not dependant on Spring. Cool. :-)
(This may not be the best design... but hey, it makes me happy today. :-)
Cheers,
Timo
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]