# spring kann eine bean nicht erzeugen



## JRookie (9. Sep 2011)

Hallo zusammen,
ich sitz hier nun schon 2 Tage und weiss nicht mehr weiter.
Ich möchte eine Beispielanwendung namens sprMVCFull ans Laufen bekommen. web.xml verweist auf "controller", controller.xml sieht so aus
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

    <bean id="controllerMapping"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/index.html">indexController</prop>
                <prop key="/hello.html">homeController</prop>
                <prop key="/printCommand.html">printCommandController</prop>
                <prop key="/processDetails.html">processDetailsController</prop>
                <prop key="/survey.html">surveyController</prop>
            </props>
        </property>
    </bean>

	<bean id="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location" value="classpath:views.properties" />
	</bean>



    <bean id="indexController" class="sprMVCFull.controller.IndexController">
    </bean>

    <bean id="homeController" class="sprMVCFull.controller.HomeController">
        <property name="greeting">
            <value>Welcome to Spring MVC</value>
        </property>
    </bean>

    <bean id="printCommandController" class="sprMVCFull.controller.PrintParamController">
    </bean>

    <bean id="processDetailsController" class="sprMVCFull.controller.ProcessDetailsController">
        <property name="formView">
            <value>processDetails</value>
        </property>
        <property name="validator">
            <bean class="sprMVCFull.model.PersonValidator"/>
        </property>
    </bean>

    <bean id="surveyController" class="sprMVCFull.controller.SurveyController">
        <property name="pages">
            <list>
                <value>survey_colour_food</value>
                <value>survey_country_language</value>
                <value>survey_film_singer</value> 
            </list>
        </property>
    </bean>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
        <property name="basename">
            <value>views</value>
        </property>
    </bean>

    <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename">
            <value>messages</value>
        </property>
    </bean>

</beans>
[/XML]
dazu gibt es eine views.properties Datei, die fogendermassen aussieht:
[XML]home.class=org.springframework.web.servlet.view.JstlView
home.url=/WEB-INF/jsp/home.jsp

index.class=org.springframework.web.servlet.view.JstlView
index.url=/WEB-INF/jsp/index.jsp

printCommand.class=org.springframework.web.servlet.view.JstlView
printCommand.url=/WEB-INF/jsp/printCommand.jsp

processDetails.class=org.springframework.web.servlet.view.JstlView
processDetails.url=/WEB-INF/jsp/processDetails.jsp

survey_colour_food.class=org.springframework.web.servlet.view.JstlView
survey_colour_food.url=/WEB-INF/jsp/survey_colour_food.jsp

survey_country_language.class=org.springframework.web.servlet.view.JstlView
survey_country_language.url=/WEB-INF/jsp/survey_country_language.jsp

survey_film_singer.class=org.springframework.web.servlet.view.JstlView
survey_film_singer.url=/WEB-INF/jsp/survey_film_singer.jsp

[/XML]
M.E. wird hier der Zusammenhang zwischen z.B. "survey_film_singer" und der dazugehörenden jsp verdrahtet.
Wenn ich tomcat hochfahre kann ich sehen, dass die properties gefunden werden und die singletons erzeugt werden:
[XML]INFO: Deploying web application archive sprMVCFull.war
09.09.2011 17:40:37 org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(F:\Entwicklung\Apache Software Foundation\Apache Tomcat 6.0.14\webapps\sprMVCFull\WEB-INF\lib\javax.servlet.jar) - jar not l
oaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
09.09.2011 17:40:37 org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(F:\Entwicklung\Apache Software Foundation\Apache Tomcat 6.0.14\webapps\sprMVCFull\WEB-INF\lib\servlet-api-2.5.jar) - jar not
 loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
09.09.2011 17:40:37 org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'controller': initialization started
09.09.2011 17:40:37 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'controller-servlet': startup date [Fri Sep 09 17:40:37 CEST 2011]; root of context hierarchy

09.09.2011 17:40:37 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/controller-servlet.xml]
09.09.2011 17:40:37 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [views.properties]
09.09.2011 17:40:37 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@cb754f: defining beans [controllerMappi
ng,propertyPlaceholder,indexController,homeController,printCommandController,processDetailsController,surveyController,viewResolver,messageSource]
; root of factory hierarchy
09.09.2011 17:40:37 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/survey.html] onto handler [sprMVCFull.controller.SurveyController@1612190]
09.09.2011 17:40:37 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello.html] onto handler [sprMVCFull.controller.HomeController@c736e4]
09.09.2011 17:40:37 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/processDetails.html] onto handler [sprMVCFull.controller.ProcessDetailsController@ad5fab]
09.09.2011 17:40:37 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/index.html] onto handler [sprMVCFull.controller.IndexController@63f09e]
09.09.2011 17:40:37 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/printCommand.html] onto handler [sprMVCFull.controller.PrintParamController@d36ff3]
09.09.2011 17:40:38 org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'controller': initialization completed in 797 ms
[/XML]
Sieht doch gut aus, oder???
Wenn ich nun im browser den Aufruf mache: http://localhost:8080/sprMVCFull/hello.html
bekomme ich die Fehlermeldung:
[XML]org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'survey_film_singer': Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition[/XML]
und tomcat erzeugt und zerstört direkt wieder die singletons:
[XML]2011 17:40:59 org.springframework.context.support.AbstractApplicationContext prepareRefresh
Refreshing org.springframework.web.context.support.GenericWebApplicationContext@4de3fe: startup date [Fri Sep 09 17:40:59 CEST 2011]; parent
pplicationContext for namespace 'controller-servlet'
2011 17:40:59 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@21b42f: defining beans [survey_film_sin
intCommand,index,survey_country_language,processDetails,survey_colour_food,home]; parent: org.springframework.beans.factory.support.DefaultL
eBeanFactory@cb754f
2011 17:40:59 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@21b42f: defining beans [survey_film_singer,pri
and,index,survey_country_language,processDetails,survey_colour_food,home]; parent: org.springframework.beans.factory.support.DefaultListable
ctory@cb754f
[/XML]
SurveyController.java sieht so aus:

```
package sprMVCFull.controller;

//  import org.springframework.web.servlet.mvc.AbstractWizardFormController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractWizardFormController;

import sprMVCFull.model.Survey;

@SuppressWarnings("deprecation")
public class SurveyController extends AbstractWizardFormController
{
    public SurveyController()
    {
        setCommandClass(Survey.class);
    }

    protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response,
                                         Object command, BindException errors)
            throws Exception
    {
    	  System.out.println("XXXX  Hallo, hier in SurveyController.class in processFinish XXXX");
        Survey survey = (Survey) command ;
        return new ModelAndView("printCommand", "command", survey) ;
    }

    protected ModelAndView processCancel(HttpServletRequest request, HttpServletResponse response,
                                         Object command, BindException errors)
            throws Exception
    {
  	  System.out.println("XXXX  Hallo, hier in SurveyController.class in processCancel XXXX");
        return new ModelAndView("printCommand", "command", "survey form submission cancelled") ;

    }

    protected void validatePage(Object command, Errors errors, int page, boolean finish)
    {
        Survey survey = (Survey) command ;
  	  System.out.println("XXXX  Hallo, hier in SurveyController.class in validatePage XXXX");
        switch (page)
        {
        case 0:
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "colour",
                                                      "required.colour", "colour is required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "food",
                                                      "required.food", "food is required");
            break ;
        case 1:
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "country",
                                                      "required.country", "country is required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "language",
                                                      "required.language", "language is required");
            break ;
        case 2:
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "film",
                                                      "required.film", "film is required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "singer",
                                                      "required.singer", "singer is required");
            break ;
        default:
        }
        if (finish)
        {
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "colour",
                                                      "required.colour", "colour is required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "food",
                                                      "required.food", "food is required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "country",
                                                      "required.country", "country is required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "language",
                                                      "required.language", "language is required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "film",
                                                      "required.film", "film is required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors,  "singer",
                                                      "required.singer", "singer is required");
            if (!"ireland".equals(survey.getCountry().toLowerCase()))
                errors.reject("invalid.country", "bad choice of favourite country (try \"Ireland\")!") ;
        }
    }
}
```
Ich bin wirklich einigermassen ratlos. Weiss jemand warum das nicht läuft??? Versionsprobleme sollten nicht die Ursache sein ich habe servlet-api-2.5.jar installiert ....
Vielen Dank im voraus für jeden Tipp
JRookie


----------



## AFlieger (9. Sep 2011)

Ich hab hierzu den folgenden link gefunden.

No bean class specified on bean definition

Scheint so, dass *class* in Klammern geschrieben werden muss.


----------



## JRookie (11. Sep 2011)

Hallo Aflieger,
Treffer !! Das ist es tatsächlich ... das Wort "class" muß in Klammern gesetzt werden. Hab ich noch nie gesehen, hab auch diesen Link nicht gefunden.
Du aber schon. Dickes Dankeschön dafür !!
Viele Grüße
JRookie


----------

