Howdy,
I started a new project today and can't figure out what I am doing wrong. I have a good classpath (built with Maven against spring-aspects 2.0, looks like everything is there transitively and no CNFs) and no errors are coming out, but I have this very peculiar behavior: This code does not work:
This code does:Code:public static void main(String[] args) { ClassPathResource resource = new ClassPathResource("applicationContext.xml"); BeanFactory factory = new XmlBeanFactory(resource); FeedManager fm = (FeedManager) factory.getBean("feedManager"); fm.processFeeds(); }
When I say "works", I mean that the call to getBean("feedManager") returns the feedManager bean wrapped with the transactional proxy code.Code:public class FeedTest extends AbstractTransactionalSpringContextTests { public void testFeed() throws Exception { FeedManager feedManager = (FeedManager)applicationContext.getBean("feedManager"); feedManager.processFeeds(); } protected String[] getConfigLocations() { return new String[] {"applicationContext.xml"}; } }
Here's my FeedManagerImpl:
In the case of the TestCase version, I get "DEBUG org.springframework.aop.framework.JdkDynamicAopPro xy - Creating JDK dynamic proxy for [foo.service.impl.FeedManagerImpl]", but I do not get that at all in the static main version.Code:@Transactional public class FeedManagerImpl extends HibernateDaoSupport implements FeedManager { public void processFeeds() { HibernateTemplate hibernateTemplate = getHibernateTemplate(); for (Feed feed : (List<Feed>) hibernateTemplate.find("from Feed")) { // do something interesting hibernateTemplate.save(...); } } }
These are both using the same context configuration file:
Any ideas what I might be missing? I tried to keep this as simple as the examples on the new docs (which look great, BTW), but have also tried a lot of different variations as well. Any help appreciated!Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location" value="classpath:hibernate.properties"/> </bean> <bean id="hibernate" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="properties"> <ref local="hibernateProperties"/> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${hibernate.connection.driver_class}"/> <property name="url" value="${hibernate.connection.url}"/> <property name="username" value="${hibernate.connection.username}"/> <property name="password" value="${hibernate.connection.password}"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value> </property> <property name="hibernateProperties"> <ref local="hibernateProperties"/> </property> </bean> <bean id="feedManager" class="foo.service.impl.FeedManagerImpl"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> </beans>


Reply With Quote
I'll go redress this deficincy immediately.