PDA

View Full Version : Troubleshooting my spring.xml - Multiple Databases



raydawg
Mar 2nd, 2006, 12:15 PM
Hello,
My web app is going to be accessing 3 databases. So i thought that I had setup this up properly in my spring file, but when i access an action mapping, ie: test.do, an error is thrown


2006-03-02 09:25:39 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'sessionFactory' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [adminLogonDAO,adminUserDAO,advisorLogonDAO,advisor RegularHoursDAO,advisorServiceRolesDAO,advisorStat usLogDAO,advisorUserDAO,departmentDAO,frontdeskLog onDAO,frontdeskStatusLogDAO,frontdeskUserDAO,servi ceCatLookupDAO,supervisorLogonDAO,supervisorStatus LogDAO,supervisorUserDAO,systemHolidaysDAO,systemS choolYearsDAO,systemSettingsDAO,userStatusLookupDA O,advisingAppointmentsDAO,advisingSummariesDAO,adv isorProfileDAO,advisorScheduleDAO,appointmentStatu sLookupDAO,nostdAnswersDAO,nostdQuestionsDAO,stdAn swerLookupDAO,stdQuestionLookupDAO,stdQuestionsDAO ,studentLogonDAO,studentUserDAO,addAdvisingSummary SvcTarget,cancelStudentAppointmentSvcTarget,editSc heduleSvcTarget,enterStudentInformationSvcTarget,s cheduleStudentAppointmentSvcTarget,transferAnAppoi ntmentSvcTarget,veiwGroupScheduleSvcTarget,veiwStu dentHistorySvcTarget,veiwStudentInformationSvcTarg et,managerMainDataSource,advisingMainDataSource,su rveyMainDataSource,advisingSessionFactory,managerS essionFactory,surveySessionFactory,advisingTxManag er,managerTxManager,surveyTxManager,mailSender,war ehouse]; root of BeanFactory hierarchy
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:307)
at


This sounds like its saying that there must be a bean defined sessionFactory, and that I cannot use the beanId's that I used advisingSessionFactor, etc... So my question I guess is that do i have to have a bean defined sessionFactory? and if i do how would i do that so that I can use these 3 databases? I have done complete searches through my whole project and there is not any references to sessionFacotry. Below is my spring.xml file
Thanks
-Ray




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<!--
Reference to Manager Database DAOs config file
-->
<import resource="spring-Manager-DAOs.xml"/>

<!--
Reference to Advising Database DAOs config file
-->
<import resource="spring-Advising-DAOs.xml"/>

<!--
Reference to Advising Database DAOs config file
-->
<import resource="spring-Survey-DAOs.xml"/>

<!--
Service Layer Definitions for Advisor use cases
-->
<import resource="spring-Advisor-Services.xml"/>

[....]Database definitions[....]

<bean id="advisingSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="dataSource">
<ref bean="advisingMainDataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>/mappings/Advising/AdminLogon.hbm.xml</value>
<value>/mappings/Advising/AdminUser.hbm.xml</value>
<value>/mappings/Advising/AdvisingAppointments.hbm.xml</value>
<value>/mappings/Advising/AdvisingSummaries.hbm.xml</value>
<value>/mappings/Advising/AdvisorLogon.hbm.xml</value>
<value>/mappings/Advising/AdvisorProfile.hbm.xml</value>
<value>/mappings/Advising/AdvisorUser.hbm.xml</value>
<value>/mappings/Advising/AdvisorSchedule.hbm.xml</value>
<value>/mappings/Advising/AppointmentStatusLookup.hbm.xml</value>
<value>/mappings/Advising/NostdAnswers.hbm.xml</value>
<value>/mappings/Advising/NostdQuestions.hbm.xml</value>
<value>/mappings/Advising/ScheduleCodeLookup.hbm.xml</value>
<value>/mappings/Advising/StdAnswerLookup.hbm.xml</value>
<value>/mappings/Advising/StdQuestionLookup.hbm.xml</value>
<value>/mappings/Advising/StdQuestions.hbm.xml</value>
<value>/mappings/Advising/StudentLogon.hbm.xml</value>
<value>/mappings/Advising/StudentUser.hbm.xml</value>
<value>/mappings/Advising/SupervisorLogon.hbm.xml</value>
<value>/mappings/Advising/SupervisorUser.hbm.xml</value>
</list>
</property>
</bean>
<bean id="managerSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="dataSource">
<ref bean="managerMainDataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>/mappings/Manager/AdminLogon.hbm.xml</value>
<value>/mappings/Manager/AdminUser.hbm.xml</value>
<value>/mappings/Manager/AdvisorRegularHours.hbm.xml</value>
<value>/mappings/Manager/AdvisorServiceRoles.hbm.xml</value>
<value>/mappings/Manager/AdvisorStatusLog.hbm.xml</value>
<value>/mappings/Manager/AdvisorLogon.hbm.xml</value>
<value>/mappings/Manager/AdvisorUser.hbm.xml</value>
<value>/mappings/Manager/Department.hbm.xml</value>
<value>/mappings/Manager/FrontdeskLogon.hbm.xml</value>
<value>/mappings/Manager/FrontdeskStatusLog.hbm.xml</value>
<value>/mappings/Manager/FrontdeskUser.hbm.xml</value>
<value>/mappings/Manager/ServiceCatLookup.hbm.xml</value>
<value>/mappings/Manager/SupervisorLogon.hbm.xml</value>
<value>/mappings/Manager/SupervisorUser.hbm.xml</value>
<value>/mappings/Manager/SupervisorStatusLog.hbm.xml</value>
<value>/mappings/Manager/SystemHolidays.hbm.xml</value>
<value>/mappings/Manager/SystemSchoolYears.hbm.xml</value>
<value>/mappings/Manager/SystemSettings.hbm.xml</value>
<value>/mappings/Manager/UserStatusLookup.hbm.xml</value>
</list>
</property>
</bean>

<bean id="surveySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="dataSource">
<ref bean="surveyMainDataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>/mappings/Survey/SurveyBasicInfo.hbm.xml</value>
</list>
</property>
</bean>

<bean id="advisingTxManager"
class="org.springframework.orm.hibernate3.HibernateTransa ctionManager">
<property name="sessionFactory"><ref local="advisingSessionFactory"/></property>
<property name="dataSource"><ref local="advisingMainDataSource"/></property>
</bean>

<bean id="managerTxManager"
class="org.springframework.orm.hibernate3.HibernateTransa ctionManager">
<property name="sessionFactory"><ref local="managerSessionFactory"/></property>
<property name="dataSource"><ref local="managerMainDataSource"/></property>
</bean>

<bean id="surveyTxManager"
class="org.springframework.orm.hibernate3.HibernateTransa ctionManager">
<property name="sessionFactory"><ref local="surveySessionFactory"/></property>
<property name="dataSource"><ref local="surveyMainDataSource"/></property>
</bean>

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderIm pl">
<property name="host"><value>smtp.ucr.edu</value></property>
</bean>

<!--
Create the warehouse so it will already have a connection and keep a
refernce so it won't get GC'd
-->
<bean id="warehouse"
class="org.springframework.beans.factory.config.MethodInv okingFactoryBean"
lazy-init="true">
<property name="staticMethod">
<value>edu.ucr.c3.ucrwarehouse.WarehouseFactory.createWar ehouse</value>
</property>
</bean>

<!--
Configure velocity for our e-mail templates

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFact oryBean">
<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>
</props>
</property>
</bean>
-->

<!-- define a task that will call the synchronizeData method of a service bean
to keep our data synchronized

<bean id="dataSyncJob" class="org.springframework.scheduling.quartz.MethodInvoki ngJobDetailFactoryBean">
<property name="targetObject"><ref bean="academicService"/></property>
<property name="targetMethod"><value>synchronizeData</value></property>
<property name="concurrent"><value>false</value></property>
</bean>

<bean id="dailyDataSync" class="org.springframework.scheduling.quartz.CronTriggerB ean">
<property name="jobDetail">
<ref bean="dataSyncJob"/>
</property>
<property name="cronExpression">
<value>0 0 2 * * ? </value>
</property>
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFac toryBean">
<property name="triggers">
<list>
<ref local="dailyDataSync"/>
</list>
</property>
<property name="autoStartup"><value>true</value></property>
</bean> -->

</beans>

raydawg
Mar 2nd, 2006, 04:53 PM
ok I think i found the source of the proble, but i have no solution...This is from my web.xml file


<!-- Configuration for spring application context -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring.xml</param-value>
<!-- <description>Location of spring config file.</description> -->
</context-param>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListe ner
</listener-class>
</listener>


<!-- Servlet filter to be used when hibernate is the backend to keep the
session open for the jsp pages.
-->
<filter>
<filter-name>HibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter</filter-class>
</filter>

and when i looked at the source for OpenSessionInViewFilter it has this


public static final String DEFAULT_SESSION_FACTORY_BEAN_NAME = "sessionFactory";


private String sessionFactoryBeanName = DEFAULT_SESSION_FACTORY_BEAN_NAME;

/**
* Return the bean name of the SessionFactory to fetch from Spring's
* root application context.
*/
protected String getSessionFactoryBeanName() {
return sessionFactoryBeanName;
}


as you can see sessionFactory is being used in the actual spring source code, so basically I have to use that name. But with 3 databases in the application that is impossible to name them all sessionFactory. I really need some assistance if anyone can lead me in the right direction for this please.

Thanks
-Ray

raydawg
Mar 2nd, 2006, 05:42 PM
problem solved. In case anyone was wondering I had to redefine my hibernate filters in the web.xml file like so


<filter>
<filter-name>advisingHibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>advisingSessionFactory</param-value>
</init-param>
</filter>

then i did that for all of my databases.