java - spring BeanCreationException confusion about mapping -


trying integrate hibernate , spring ,i ran error

severe: context initialization failed org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.web.servlet.mvc.annotation.defaultannotationhandlermapping': initialization of bean failed; nested exception java.lang.illegalstateexception: cannot map handler 'org.me.spring.hib.school.web.schoolcontroller#0' url path [/allschools]: there handler of type [class org.me.spring.hib.school.web.schoolcontroller] mapped.

my controller looks like

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 null");         }         modelmap modelmap = new modelmap();         modelmap.addattribute("schoolslist", this.schooldao.getallschools());         return new modelandview("allschools", modelmap);     }  } 

i have injected dao implementation in app context file

    <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> 

i cannot make out why schoolcontroller#0 being mapped url.

this happening because have both

<context:component-scan base-package="org.me.spring.hib.school.web" /> 

and

<bean  class="org.me.spring.hib.school.web.schoolcontroller" > 

the first line auto-discover , register schoolcontroller you. explicitly declaring one, duplicate, , url-mapping clash.

you need either remove <context:component-scan>, or remove explicit bean definitions controller , dao. if latter, you'll need use autowiring inject dependencies.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -