Hi guys,
I got the following error while doing junit testing:
[junit] Null Test: Caused an ERROR
[junit] null
[junit] java.lang.ExceptionInInitializerError
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Unknown Source)
[junit] Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'manager' defined in file [D:\Workspace\stufftolet\src\service\com\stufftolet \service\applicationContext-service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'transactionManager' of bean class [org.springframework.aop.framework.ProxyFactoryBean]: Bean property 'transactionManager' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
[junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1031)
[junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:823)
[junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:345)
[junit] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:226)
[junit] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
[junit] at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:269)
[junit] at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:318)
[junit] at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:81)
[junit] at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:66)
[junit] at com.borneo.service.BaseServiceTestCase.<clinit>(Ba seServiceTestCase.java:34)
[junit] ... 5 more
[junit] Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'transactionManager' of bean class [org.springframework.aop.framework.ProxyFactoryBean]: Bean property 'transactionManager' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
[junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:831)
[junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:733)
[junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:890)
[junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:917)
[junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:906)
[junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1022)
[junit] ... 14 more
My applicationContext-resources.xml
<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:mail.properties</value>
<value>classpath:database.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<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>
</beans>
My applicationContext-hibernate.xml
<beans>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="mappingResources">
<list>
<value>com/borneo/model/users/Person.hbm.xml</value>
<value>com/borneo/model/users/UserCookie.hbm.xml</value>
<value>com/borneo/model/users/UserFavourite.hbm.xml</value>
<value>com/borneo/model/users/SuspendedUser.hbm.xml</value>
<value>com/borneo/model/users/SuspendType.hbm.xml</value>
<value>com/borneo/model/posting/Category.hbm.xml</value>
<value>com/borneo/model/posting/PostingDetails.hbm.xml</value>
<value>com/borneo/model/posting/CategorizedItem.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">@HIBERNATE-DIALECT@</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- Generic DAO - can be used when doing standard CRUD -->
<bean id="dao" class="com.borneo.dao.hibernate.BaseDAOHibernate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- LookupDAO: Hibernate implementation -->
<bean id="lookupDAO" class="com.borneo.dao.hibernate.LookupDAOHibernate ">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- UserDAO: Hibernate implementation -->
<bean id="userDAO" class="com.borneo.dao.hibernate.UserDAOHibernate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- RoleDAO: Hibernate implementation -->
<bean id="roleDAO" class="com.borneo.dao.hibernate.RoleDAOHibernate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- Geographical DAO Definition: Hibernate implementation -->
<bean id="geographicalDAO" class="com.borneo.dao.hibernate.GeographicalDAOHib ernate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- Category DAO Definition: Hibernate implementation -->
<bean id="categoryDAO" class="com.borneo.dao.hibernate.CategoryDAOHiberna te">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
</beans>
My applicationContext-service.xml
<beans>
<bean id="lookupManager" class="com.borneo.service.impl.LookupManagerImpl">
<property name="lookupDAO"><ref bean="lookupDAO"/></property>
</bean>
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.aop.framework.ProxyFact oryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- Generic manager that can be used to do basic CRUD operations on any objects -->
<bean id="manager" parent="txProxyTemplate">
<property name="target">
<bean class="com.borneo.service.impl.BaseManager">
<property name="DAO"><ref bean="dao"/></property>
</bean>
</property>
</bean>
<!-- Transaction declarations for business services. To apply a generic transaction proxy to
all managers, you might look into using the BeanNameAutoProxyCreator -->
<bean id="userManager" parent="txProxyTemplate">
<property name="target">
<bean class="com.borneo.service.impl.UserManagerImpl">
<property name="userDAO"><ref bean="userDAO"/></property>
</bean>
</property>
<!-- Override default transaction attributes b/c of LoginCookie methods -->
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED,-UserExistsException</prop>
<prop key="activate*">PROPAGATION_REQUIRED,-ActivateCodeNotExistException</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*LoginCookie">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
<property name="preInterceptors">
<list>
<ref bean="userSecurityInterceptor"/>
</list>
</property>
</bean>
<bean id="mailEngine" class="com.borneo.service.MailEngine">
<property name="mailSender"><ref bean="mailSender"/></property>
<property name="velocityEngine"><ref bean="velocityEngine"/></property>
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
<property name="host"><value>${mail.host}</value></property>
<property name="username"><value>${mail.username}</value></property>
<property name="password"><value>${mail.password}</value></property>
</bean>
<!-- Configure Velocity for sending e-mail -->
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEng ineFactoryBean">
<property name="velocityProperties">
<props>
<prop key="resource.loader">class</prop>
<prop key="class.resource.loader.class">
org.apache.velocity.runtime.resource.loader.Classp athResourceLoader
</prop>
<prop key="velocimacro.library"></prop>
</props>
</property>
</bean>
<bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage" singleton="false">
<property name="from"><value>${mail.default.from}</value></property>
</bean>
<!-- Add new Managers here -->
<bean id="categoryManager" parent="txProxyTemplate">
<property name="target">
<bean class="com.borneo.service.impl.CategoryManagerImpl ">
<property name="categoryDAO"><ref bean="categoryDAO"/></property>
</bean>
</property>
</bean>
</beans>
and my CategoryServiceTest.java
public class CategoryServiceTest extends BaseServiceTestCase {
private CategoryManager mgr = null;
private Log log = LogFactory.getLog(CategoryManagerTest.class);
private Category cat;
protected void setUp() throws Exception {
mgr = (CategoryManager) ctx.getBean("categoryManager");
}
protected void tearDown() {
mgr = null;
}
public void testGetUser() throws Exception {
cat = (Category) mgr.getCategory(new Long(8709));
if (log.isDebugEnabled())
log.debug(cat.getId());
}
public static void main(String[] args) {
junit.textui.TestRunner.run(UserManagerTest.class) ;
}
}
the BaseServiceTestCase.java:
public class BaseServiceTestCase extends TestCase {
private static Log log = LogFactory.getLog(BaseManagerTestCase.class);
protected static ResourceBundle rb = null;
protected static ApplicationContext ctx = null;
static {
ResourceBundle db = ResourceBundle.getBundle("database");
String daoType = db.getString("dao.type");
String[] paths = {"classpath*:/**/service/applicationContext-service.xml",
"classpath*:/**/dao/applicationContext-resources.xml",
"classpath*:META-INF/applicationContext-hibernate.xml"};
ctx = new ClassPathXmlApplicationContext(paths);
}
public BaseServiceTestCase() {
String className = this.getClass().getName();
try {
rb = ResourceBundle.getBundle(className);
} catch (MissingResourceException mre) {
log.warn("No resource bundle found for: " + className);
}
}
protected Object populate(Object obj) throws Exception {
Map map = ConvertUtil.convertBundleToMap(rb);
BeanUtils.copyProperties(obj, map);
return obj;
}
}
Please help, TIA !
regards,
Mark[/b]


Reply With Quote