Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Velocity's DataSourceResourceLoader

In the current project I'm on, one of the major requirements is to have the ability to send job postings to job boards such as Monster.com, CareerBuilder.com, etc. - as well as local newspapers. When I first started this project, I went about contacting all of these advertisers and explained that we'd like to automate the process of talking to their system. I found that many of them preferred a simple e-mail with the job posting, but others wanted us to FTP a pre-formatted document to them.

I figure the easiest way to handle this is to use Velocity. By using Velocity, and storing templates in the database, users of the system can either (1) use a default template or (2) customize a template for a specific advertiser. This was all easy enough since we're using Struts Resume as a baseline for this project, and Velocity is already built-in.

I remembered seeing that Velocity had some sort of database ResourceLoader, so I went searching and found the DataSourceResourceLoader:

This loader will load resources from a DataSource such as a database. This loader is not built as part of the standard build as it requires J2EE support. To build this loader, please download the J2EE distribution, move the j2ee.jar into the build/lib directory, and then build the new velocity jar with the jar-j2ee build target. For more information on this loader, please see the javadoc for DataSourceResourceLoader.

After checking out Velocity 1.4.1 RC1 (are they ever going to release this thing?) from CVS, I was able to build a new Velocity JAR. To compile using J2EE 1.4, you have to modify the VelocityServletTest, or delete it. I then replaced velocity-1.4-rc1.jar with this new JAR (which is actually 4KB smaller), configured velocity.properties and Voila - it worked! Clean and easy integration - just the way I like it.

Posted in Java at Jan 21 2004, 06:28:50 AM MST 3 Comments
Comments:

Can you show me the velocity.properties file and the piece of code that calls getTemplate ?

Posted by Ian Spence on May 11, 2004 at 12:45 AM MDT #

You can see it in my Struts Resume project: Download or checkout its CVS Repository. Here's the files you're looking for: velocity.properties and PageServlet.java.

Posted by Matt Raible on May 11, 2004 at 08:58 AM MDT #

Hi Matt, Having read your article (http://jroller.com/page/raible?anchor=loading_velocity_templates_from_the) I thought I'd try out loading velocity templates from the databases. I am, however, having problems. I am having trouble finding the source for velocity 1.4.1 RC1 - I can see 1.4 RC1 in the Subversion repository, which I can build but when I deploy I get the following error:

org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader]: Bean property 'dataSource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

Having looked at the source and the posts on velocity's JIRA it seems as though I do indeed have the wrong version.
Any idea where I can get the correct code? Perhaps I should ask the velocity group?
Thanks if you can help!

Posted by Paul Feaviour on March 13, 2006 at 11:09 AM MST #

Post a Comment:
  • HTML Syntax: Allowed