Since version 0.6 we offer a more convenient configuration of the JDBC Logger for projects that are using the Spring Framework for data source(s) setup and target drivers to wrapp. This feature takes advantage of the BeanPostProcessor interface extension point, that allows us to perform some custom logic after the Spring container finished initializing a bean, in our case, one or more data source beans.
This way you are no longer required to create a <jdbclogger.properties> file, or specify your target JDBC drivers as system properties, you can have a bean that does this automaticaly, that you can enable / disable, depending let's say, if you are or not in a development environement. Not to mention that you benefit from the full power of Spring's way of configuring beans.
For example, a data source bean:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.hsqldb.jdbcDriver"/> <property name="url" value="jdbc:hsqldb:mem:test"/> <property name="username" value="sa"/> </bean>
For configuring JDBC Logger you'll need to add the <net.sourceforge.jdbclogger.spring.JdbcLoggerBeanPostProcessor> bean to your context file, like this:
<bean id="jdbcLoggerConfig" class="net.sourceforge.jdbclogger.spring.JdbcLoggerBeanPostProcessor"> <property name="enabled" value="true"/> <property name="dataSourceConfigurations"> <list> <bean class="net.sourceforge.jdbclogger.spring.JdbcLoggerDataSourceConfiguration"> <property name="dataSourceBeanName" value="dataSource"/> <property name="driverClassNamePropertyName" value="driverClassName"/> </bean> </list> </property> <property name="targetDriverClassNames"> <list> <value>org.hsqldb.jdbcDriver</value> </list> </property> </bean>
As you notice, what it needs is a list of <JdbcLoggerDataSourceConfiguration> instances that set the names of the data source beans and the corresponding driver class name property names; as each concrete implementation of the javax.sql.DataSource interface usualy has a property called <driverClassName>, in this way, the JdbcLoggerBeanPostProcessor will be able to replace the value of the property, via reflection, with the corresponding wrapper class name at runtime.
The <targetDriverClassNames> property, is a list containing the driver class names JDBC Logger should wrapp, as besides replacing the driver names used by the data sources, it also needs to know to which actual driver to delegate the calls.
Also note that the <enabled> property has a value of 'true' by default.
If you only have one data source bean called 'dataSource' that has the driver class name specified in a property called 'driverClassName', these represent the default values the JDBC Logger knows about, and your configuration would look like the following:
<bean id="jdbcLoggerConfig" class="net.sourceforge.jdbclogger.spring.JdbcLoggerBeanPostProcessor"> <property name="targetDriverClassNames"> <list> <value>org.hsqldb.jdbcDriver</value> </list> </property> </bean>