On Wed, Jan 7, 2009 at 2:28 PM, nn4l <[email protected]> wrote: > > > mraible wrote: >> >> Can you post your applicationContext.xml file with your accountManager >> bean definition? >> > > Here is the applicationContext.xml: > > <?xml version="1.0" encoding="UTF-8"?> > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" > default-lazy-init="true"> > > <!-- Add new DAOs here --> > > > > > > <!--FolderManager-START--> > <bean id="folderManager" > class="project.service.impl.GenericManagerImpl"> > <constructor-arg> > <bean class="project.dao.hibernate.GenericDaoHibernate"> > <constructor-arg value="project.model.Folder"/> > <property name="sessionFactory" ref="sessionFactory"/> > </bean> > </constructor-arg> > </bean> > <!--FolderManager-END--> > > <!-- Add new Managers here --> > > <!-- Add new Actions here --> > </beans> > > There was a bean for "accountManager" in this file which I had to remove. > That one had been generated by "mvn appfuse:gen". The "folderManager" bean > is for a second class that does not yet have a corresponding dao. > > I have manually created a new "accountManager" entry in > applicationContext-service.xml: > > <?xml version="1.0" encoding="UTF-8"?> > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:aop="http://www.springframework.org/schema/aop" > xmlns:tx="http://www.springframework.org/schema/tx" > xsi:schemaLocation="http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.0.xsd > http://www.springframework.org/schema/aop > http://www.springframework.org/schema/aop/spring-aop-2.0.xsd > http://www.springframework.org/schema/tx > http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" > default-lazy-init="true"> > > <!-- =================================================================== > --> > <!-- AOP: Configuration and Aspects > --> > <!-- =================================================================== > --> > <aop:config> > <aop:advisor id="userManagerTx" advice-ref="userManagerTxAdvice" > pointcut="execution(* *..service.UserManager.*(..))" order="0"/> > <aop:advisor id="userManagerSecurity" > advice-ref="userSecurityAdvice" pointcut="execution(* > *..service.UserManager.saveUser(..))" order="1"/> > <aop:advisor id="managerTx" advice-ref="txAdvice" > pointcut="execution(* *..service.*Manager.*(..))" order="2"/> > </aop:config> > > <!-- Enable @Transactional support --> > <tx:annotation-driven/> > > <!-- Enable @AspectJ support --> > <aop:aspectj-autoproxy/> > > <!-- Enable @Configured support --> > <aop:spring-configured/> > > <tx:advice id="txAdvice"> > <tx:attributes> > <!-- Read-only commented out to make things easier for end-users > --> > <!-- http://issues.appfuse.org/browse/APF-556 --> > <!--tx:method name="get*" read-only="true"/--> > <tx:method name="*"/> > </tx:attributes> > </tx:advice> > > <tx:advice id="userManagerTxAdvice"> > <tx:attributes> > <tx:method name="save*" rollback-for="UserExistsException"/> > </tx:attributes> > </tx:advice> > > <bean id="userSecurityAdvice" > class="project.service.UserSecurityAdvice"/> > > <!-- =================================================================== > --> > <!-- Mail: Sender and Velocity configuration > --> > <!-- =================================================================== > --> > <bean id="mailEngine" class="project.service.MailEngine"> > <property name="mailSender" ref="mailSender"/> > <property name="velocityEngine" ref="velocityEngine"/> > <property name="from" value="${mail.default.from}"/> > </bean> > > <bean id="mailSender" > class="org.springframework.mail.javamail.JavaMailSenderImpl"> > <property name="host" value="${mail.host}"/> > <property name="defaultEncoding" value="UTF-8"/> > <!-- Uncomment if you need to authenticate with your SMTP Account > --> > <!--property name="username" value="${mail.username}"/> > <property name="password" value="${mail.password}"/> > <property name="javaMailProperties"> > <value> > mail.smtp.auth=true > </value> > </property--> > </bean> > > <!-- Configure Velocity for sending e-mail --> > <bean id="velocityEngine" > class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> > <property name="velocityProperties"> > <props> > <prop key="resource.loader">class</prop> > <prop key="class.resource.loader.class"> > > org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader > </prop> > <prop key="velocimacro.library"></prop> > </props> > </property> > </bean> > > <bean id="mailMessage" > class="org.springframework.mail.SimpleMailMessage" scope="prototype"> > <property name="from" value="${mail.default.from}"/> > </bean> > > <!-- =================================================================== > --> > <!-- Security class from Spring Security - used to configure Password > --> > <!-- Encryption in UserManagerImpl. Can override in security.xml. > --> > <!-- =================================================================== > --> > <bean id="passwordEncoder" > class="org.springframework.security.providers.encoding.ShaPasswordEncoder"/> > > <!-- =================================================================== > --> > <!-- Managers: For accessing DAOs > --> > <!-- =================================================================== > --> > <bean id="manager" class="project.service.impl.UniversalManagerImpl"> > <property name="dao" ref="universalDao"/> > </bean> > > <bean id="lookupManager" class="project.service.impl.LookupManagerImpl"> > <property name="lookupDao" ref="lookupDao"/> > </bean> > > <bean id="userManager" class="project.service.impl.UserManagerImpl"> > <property name="userDao" ref="userDao"/> > <property name="passwordEncoder" ref="passwordEncoder"/> > </bean> > > <bean id="roleManager" class="project.service.impl.RoleManagerImpl"> > <property name="roleDao" ref="roleDao"/> > </bean> > > <!-- Add new Managers here --> > > <bean id="accountManager" > class="project.service.impl.AccountManagerImpl"> > <property name="accountDao" ref="accountDao"/> > </bean> > > </beans> > > > And here is the content of applicationContext-dao.xml, where I added > manually the accountDao entry: > > <?xml version="1.0" encoding="UTF-8"?> > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" > default-lazy-init="true"> > > <!-- Hibernate SessionFactory --> > <bean id="sessionFactory" > class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> > <property name="dataSource" ref="dataSource"/> > <property name="configLocation" > value="classpath:hibernate.cfg.xml"/> > <property name="hibernateProperties"> > <value> > hibernate.dialect=${hibernate.dialect} > hibernate.query.substitutions=true 'Y', false 'N' > hibernate.cache.use_second_level_cache=true > > hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider > </value> > <!-- Turn batching off for better error messages under > PostgreSQL --> > <!-- hibernate.jdbc.batch_size=0 --> > </property> > </bean> > > <!-- Transaction manager for a single Hibernate SessionFactory > (alternative to JTA) --> > <bean id="transactionManager" > class="org.springframework.orm.hibernate3.HibernateTransactionManager"> > <property name="sessionFactory" ref="sessionFactory"/> > </bean> > > <!-- UniversalDao - can be used when doing standard CRUD - made > available > for those who don't mind casting. If you don't want to cast, look > at > 'fooDao' below. --> > <bean id="universalDao" > class="project.dao.hibernate.UniversalDaoHibernate"> > <property name="sessionFactory" ref="sessionFactory"/> > </bean> > > <bean id="lookupDao" class="project.dao.hibernate.LookupDaoHibernate"> > <property name="sessionFactory" ref="sessionFactory"/> > </bean> > > <bean id="userDao" class="project.dao.hibernate.UserDaoHibernate"> > <property name="sessionFactory" ref="sessionFactory"/> > </bean> > > <bean id="roleDao" class="project.dao.hibernate.RoleDaoHibernate"> > <property name="sessionFactory" ref="sessionFactory"/> > </bean> > > <!-- If you want to be able to do simple CRUD for new domain objects > without > having to cast, you don't have create a Dao interface and > implementation > for that domain object, you simply have to do the following. > > eg... 'fooDao' > > <bean id="fooDao" class="project.dao.hibernate.GenericDaoHibernate"> > <constructor-arg value="project.model.Foo"/> > <property name="sessionFactory" ref="sessionFactory"/> > </bean> > > You will need to create a Dao interface and implementation for that > domain object if you need more than simple CRUD to occur. > (finders, bulk update/delete, etc.) > --> > > <!-- Add new DAOs here --> > > <bean id="accountDao" class="project.dao.hibernate.AccountDaoHibernate"> > <property name="sessionFactory" ref="sessionFactory"/> > </bean> > > </beans> > > > What I don't understand: when running mvn jetty:run everything is fine - so > these entries can't be that wrong. When running the JUnit tests from within > IDEA, the AccountDao object is in fact created during creation of the > AccountManager object, so the systems seems to see both > applicationContext-dao.xml and applicationContext-service.xml. But the > AccountDao object is never sent to the AccountManager object.
If you run the JUnit test from the command line, does it pass? The problem is likely that the context files loaded in your test are different from the ones loaded in web.xml. You also might want to check for duplicate applicationContext*.xml files. Matt --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
