|
From: Matt R. <li...@ra...> - 2004-04-28 03:20:49
|
I've been talking with some Velocity folks about modifying their DataSourceResourceLoader to allow setting the DataSource (currently it makes you specify a JNDI string in your properties). They have done this and provided a patch: http://issues.apache.org/bugzilla/show_bug.cgi?id=28611 This is my idea of how it would be configured in Spring: <!-- Configure Velocity for sending e-mail --> <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean" singleton="true"> <property name="velocityProperties"> <props> <prop key="resource.loader">ds</prop> <prop key="ds.resource.loader.resource.table">template</prop> <prop key="ds.resource.loader.resource.keycolumn">name</prop> <prop key="ds.resource.loader.resource.templatecolumn">content</prop> <prop key="ds.resource.loader.resource.timestampcolumn">last_modified</prop> </props> </property> <property name="resourceLoader"><ref local="templateLoader"/></property> </bean> <bean id="templateLoader" singleton="true" class="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoa der"> <property name="dataSource"><ref local="dataSource"/></property> </bean> However, I get the following error: [junit] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityEngine' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader] to required type [org.springframework.core.io.ResourceLoader] for property 'resourceLoader'; nested exception is java.lang.IllegalArgumentException: argument type mismatch] Is it possible to allow this, or some other way of initializing this ResourceLoader and putting it in the Engine? Here's the code you can use if you were programming this: DataSourceResourceLoader ds = new DataSourceResourceLoader(); ds.setDataSource(DATASOURCE); Velocity.setProperty("ds.resource.loader.instance",ds); Velocity.init(); Thanks, Matt |