cercando di integrare Hibernate e la primavera, mi sono imbattuto in questo erroreprimavera BeanCreationException confusione sulla mappatura
GRAVI: l'inizializzazione non è riuscita Contesto
org.springframework.beans.factory.BeanCreationException
: Errore durante la creazione di fagioli con nome 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
': inizializzazione di Bean non è riuscito; l'eccezione nidificata èjava.lang.IllegalStateException
: Impossibile mappare il gestore "org.me.spring.hib.school.web.SchoolController#0
" al percorso URL [/allschools
]: è già associato il gestore del tipo [classeorg.me.spring.hib.school.web.SchoolController
] mappato.
mio controller sembra
package org.me.spring.hib.school.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.me.spring.hib.school.dao.SchoolDAO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SchoolController {
private SchoolDAO schoolDao;
public SchoolDAO getSchoolDao() {
return schoolDao;
}
public void setSchoolDao(SchoolDAO schoolDao) {
this.schoolDao = schoolDao;
}
@RequestMapping("/allschools")
public ModelAndView showAllSchools(HttpServletRequest request,HttpServletResponse response) throws Exception{
if(this.schoolDao ==null){
System.out.println("this.schoolDao is null");
}
ModelMap modelMap = new ModelMap();
modelMap.addAttribute("schoolsList", this.schoolDao.getAllSchools());
return new ModelAndView("allschools", modelMap);
}
}
ho iniettato l'attuazione dao in App file di contesto
<context:component-scan base-package="org.me.spring.hib.school.web" />
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" >
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="annotatedClasses">
<list>
<value>org.me.spring.hib.school.domain.School</value>
<value>org.me.spring.hib.school.domain.Teacher</value>
<value>org.me.spring.hib.school.domain.Student</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="schoolDao" class="org.me.spring.hib.school.dao.SchoolDAOImpl">
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
<bean class="org.me.spring.hib.school.web.SchoolController" >
<property name="schoolDao" ref="schoolDao" />
</bean>
non riesco a capire il motivo per cui si sta SchoolController#0
mappato all'URL.
grazie skaffman .. – markjason72