|
From: <jue...@we...> - 2004-04-28 07:23:37
|
Matt,
=20
VelocityEngineFactoryBean's "resourceLoader" property is meant to take =
an implementation of Spring's org.springframework.core.io.ResourceLoader =
interface. When setting this, VelocityEngineFactoryBean will =
auto-configure the Velocity resource loader to load file-based templates =
via the Spring ResourceLoader. When running in an ApplicationContext, =
the context will set itself as the ResourceLoader, through the =
ResourceLoaderAware interface (implemented by =
VelocityEngineFactoryBean).
=20
What you need to do in your scenario is to set Velocity's =
"ds.resource.loader.instance" property accordingly. Unfortunately, =
VelocityEngineFactoryBean's "velocityProperties" property takes a =
java.util.Properties instance, just intended for String values. So I've =
just added a "velocityPropertiesMap" property that takes a =
java.util.Map, allowing for non-String values:
=20
<bean id=3D"velocityEngine"=20
class=3D"org.springframework.ui.velocity.VelocityEngineFactoryBean"=20
singleton=3D"true">
<property name=3D"velocityProperties">
<props>
<prop key=3D"resource.loader">ds</prop>
<prop=20
key=3D"ds.resource.loader.resource.table">template</prop>
<prop=20
key=3D"ds.resource.loader.resource.keycolumn">name</prop>
<prop=20
key=3D"ds.resource.loader.resource.templatecolumn">content</prop>
<prop=20
key=3D"ds.resource.loader.resource.timestampcolumn">last_modified</prop>
</props>
</property>
<property name=3D"velocityPropertiesMap">
<map>
<entry key=3D"ds.resource.loader.instance"><ref =
bean=3D"dataSource"/></prop>
</map>
</property>
</bean>
Of course, you can also define all your Velocity properties via =
"velocityPropertiesMap": You need to use the <map>/<entry> syntax for =
all properties then, though, wrapping all your String values with =
<value> tags.
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag =
von Matt Raible
Gesendet: Mi 28.04.2004 05:20
An: spr...@li...
Betreff: [Springframework-developer] Wiring VelocityEngine with a =
DataSourceResourceLoader
I've been talking with some Velocity folks about modifying their=20
DataSourceResourceLoader to allow setting the DataSource (currently it=20
makes you specify a JNDI string in your properties). They have done=20
this and provided a patch:
http://issues.apache.org/bugzilla/show_bug.cgi?id=3D28611
This is my idea of how it would be configured in Spring:
<!-- Configure Velocity for sending e-mail -->
<bean id=3D"velocityEngine"=20
class=3D"org.springframework.ui.velocity.VelocityEngineFactoryBean"=20
singleton=3D"true">
<property name=3D"velocityProperties">
<props>
<prop key=3D"resource.loader">ds</prop>
<prop=20
key=3D"ds.resource.loader.resource.table">template</prop>
<prop=20
key=3D"ds.resource.loader.resource.keycolumn">name</prop>
<prop=20
key=3D"ds.resource.loader.resource.templatecolumn">content</prop>
<prop=20
key=3D"ds.resource.loader.resource.timestampcolumn">last_modified</prop>
</props>
</property>
<property name=3D"resourceLoader"><ref=20
local=3D"templateLoader"/></property>
</bean>
<bean id=3D"templateLoader" singleton=3D"true"
=20
class=3D"org.apache.velocity.runtime.resource.loader.DataSourceResourceLo=
a
der">
<property name=3D"dataSource"><ref =
local=3D"dataSource"/></property>
</bean>
However, I get the following error:
[junit] Caused by:=20
org.springframework.beans.factory.BeanCreationException: Error creating=20
bean with name 'velocityEngine' defined in class path resource=20
[applicationContext.xml]: Error setting property values; nested=20
exception is=20
org.springframework.beans.PropertyAccessExceptionsException:=20
PropertyAccessExceptionsException (1 errors); nested=20
propertyAccessExceptions are:=20
[org.springframework.beans.TypeMismatchException: Failed to convert=20
property value of type=20
[org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader]=20
to required type [org.springframework.core.io.ResourceLoader] for=20
property 'resourceLoader'; nested exception is=20
java.lang.IllegalArgumentException: argument type mismatch]
Is it possible to allow this, or some other way of initializing this=20
ResourceLoader and putting it in the Engine? Here's the code you can=20
use if you were programming this:
DataSourceResourceLoader ds =3D new DataSourceResourceLoader();
ds.setDataSource(DATASOURCE);
Velocity.setProperty("ds.resource.loader.instance",ds);
Velocity.init();
Thanks,
Matt
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3D3149&alloc_id=3D8166&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|