java - Spring MVC: Controller does not run in an ApplicationContext -


i trying implement webapp using spring mvc framework. far, helloworld wasn't problem. wanted read in data database. so, implemente class called dataprovider handles database access.

now added dataprovider class helloworld class, controller here. that, following exception:

java.lang.illegalstateexception: applicationobjectsupport instance [de.bpm.keza.ui.srv.kennzahlen.controller.hellocontroller@7361b599] not run in applicationcontext 

here dispatcher-servlet:

    <?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" 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-3.0.xsd        http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-3.0.xsd">     <context:component-scan base-package="de.bpm.keza.ui.srv.kennzahlen" />     <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">       <property name="prefix" value="/web-inf/templates/" />       <property name="suffix" value=".jsp" />    </bean>      <!-- externe konfigurationsdateien -->     <bean id="datasource" class="org.springframework.jndi.jndiobjectfactorybean">         <property name="jndiname"  value="jdbc/bpm_kore_alias"/>     </bean>      <!-- dataprovider -->     <bean id="dataprovider" class="de.bpm.keza.ui.srv.kennzahlen.data.dataprovider">         <property name="datasource">             <ref bean="datasource" />         </property>      <!-- keza dashboard -->     <property name="korevorgaengegesamtdatasql">             <value>                 select                      *                 de_bpm_kore_dbrd             </value>     </property>     </bean>  </beans> 

here hellocontroller.java

@controller public class hellocontroller extends webcontentgenerator {       dataprovider dapro = ((dataprovider) getwebapplicationcontext().getbean("dataprovider", dataprovider.class));     @requestmapping("/hello")     public modelandview helloworld() {         string message = "hello world, spring 3.0!";         return new modelandview("hello", "message", message);     }     @requestmapping("/bye")     public modelandview byeworld() {         string message = "goodbye world, spring 3.0!";  //          dapro.getvorgaengegesamtbyarknr();          return new modelandview("hello", "message", message);     } 

}

what doing wrong here?

you have 2 ways accessing bean.

dataprovider dapro = ((dataprovider) getwebapplicationcontext().getbean("dataprovider", dataprovider.class)); 

replace above code with

dataprovider dataprovider; 

or

@autowired dataprovider dataprovider; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -