wood burning stoves 2.0*
The moose likes Spring and the fly likes Getting a headage..... Cannot find class [...] for bean with name '...' defined in ServletContext re Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Getting a headage..... Cannot find class [...] for bean with name Watch "Getting a headage..... Cannot find class [...] for bean with name New topic
Author

Getting a headage..... Cannot find class [...] for bean with name '...' defined in ServletContext re

Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 22
I am new to Spring so bare with me... based on the "Introduction to
the Spring Framework" on netbeans.org i am trying out a demo/learn
Spring application. Although i THINK i did it right i still am not
able to deploy it from netbeans to my Tomcat 6 server. When i deploy
the application i get the following error in the tomcat.log;
SEVERE: Exception sending context initialized event to listener
instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot
find class [service.KlachtService] for bean with name 'klachtService'
defined in ServletContext resource [/WEB-INF/applicationContext.xml];
nested exception is java.lang.ClassNotFoundException:
service.KlachtService
at
org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanCl ass(AbstractBeanFactory.java:
1160)
I do not understand why the KlachtService.java in package service
could not be found. The class does exist in the indicated package and
as far as i understand is correctly defined in the
applicationContext.xml.
web.xml
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
redirect.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("klachtView.htm"); %>
dispatcher-servlet.xml
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="klachtView.htm">indexController</prop>
</props>
</property>
</bean>
<bean class="controller.KlachtFormController" p:klachtService-
ref="klachtService"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="klachtView" />
applicationContext.xml
<bean id="klachtService" class="service.KlachtService"/>
sourcepackages
controller
Klacht.java
KlachtFormController.java
model
service
KlachtService.java

Peter
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Is your class here : WEB-INF/classes/service/KlachtService.class ? Or did you package it in a JAR and put it under WEB-INF/lib ?


[My Blog]
All roads lead to JavaRanch
Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 22
Hi Cristophe,

I used a vanilla Spring Project setup from netbeans and created a new class in package service. When i build the WAR file the KlachtService.class is at WEB-INF/classes/service/KlachtService.class

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What about the exploded directory under webapps/<yourapp> ? Is the class file in there too ?
Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 22
The application Opdracht_3 is not under the tomcat webapps directory, there is a directory Opdracht_3 under the work/Catalina/localhost which contains a SESSIONS.ser of 4KB containing unreadable data. When executing a clean from netbeans this directory is cleaned. After a clean and deploy the run-deploy logfile is;

init:
deps-module-jar:
deps-ear-jar:
deps-jar:
Created dir: /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/classes
Created dir: /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/META-INF
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/META-INF
Copying 11 files to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web
library-inclusion-in-archive:
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
Copying 1 file to /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/lib
library-inclusion-in-manifest:
Created dir: /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/empty
Copied 2 empty directories to 2 empty directories under /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web/WEB-INF/classes
compile:
compile-jsps:
In-place deployment at /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web
Deployment is in progress...
deploy?config=file%3A%2Fvar%2Ffolders%2Fkt%2FktrRmEn8H5mgOFuhYb%2B-%2Bk%2B%2B%2BTI%2F-Tmp-%2Fcontext2484466420657844027.xml&path=/Opdracht_3
FAIL - Deployed application at context path /Opdracht_3 but context failed to start
/Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/nbproject/build-impl.xml:600: The module has not been deployed.
BUILD FAILED (total time: 1 second)

After the run-deploy action the war file is not deployed under webapps, but the again under work/Catalina/localhost.

If i build the war file and manually it deploy it to the webapps directory, it is successfully deployed but when started reports the error 'Neither BindingResult nor plain target object for bean name 'klacht' available as request attribute' for '/WEB-INF/jsp/klachtView.jsp'.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

If i build the war file and manually it deploy it to the webapps directory, it is successfully deployed but when started reports the error 'Neither BindingResult nor plain target object for bean name 'klacht' available as request attribute' for '/WEB-INF/jsp/klachtView.jsp'.

That's a different problem now. What does your JSP look like ?
Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 22
When i deploy from netbeans is does a in-place deployment, so probably this is the reason why it does not show up in my webapps directory.



=================
= dispatcher-servlet.xml =
=================




==================
= applicationContext.xml =
==================


====================
= KlachtFormController.class =
====================




==========
= Klacht.class =
==========



=============
= KlachtView.jsp =
=============




My expectation (based on the example) was that the Klacht bean was added to the session, but i missed probably something on the way. I assume that the tag <spring:nestedPath path=""> does not actually check the path, but just prepends this to the name of the field before binding?

Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 22
Just solved one issue now by renaming the KlachtFormController.java to KlachtController.java and change the bean definition in the dispatcher-servlet.xml.
When building a war file, deploying it to the webapps directory the application starts, processes the form and forwards the request to the KlachSuccesView.jsp.

Still when executing a clean-and-deploy from netbeans i get the error;

init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
Undeploying ...
undeploy?path=/Opdracht_3
OK - Undeployed application at context path /Opdracht_3
In-place deployment at /Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/build/web
Deployment is in progress...
deploy?config=file%3A%2Fvar%2Ffolders%2Fkt%2FktrRmEn8H5mgOFuhYb%2B-%2Bk%2B%2B%2BTI%2F-Tmp-%2Fcontext8157385603277992294.xml&path=/Opdracht_3
FAIL - Deployed application at context path /Opdracht_3 but context failed to start
/Users/petervannes/Documents/Zakelijk/OU KHO /NetBeansProjects/Opdracht_3/nbproject/build-impl.xml:600: The module has not been deployed.
BUILD FAILED (total time: 1 second)


Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 22
Ok,

Last issue also solved...



Just before the "FAIL - ..." message it reports that "deploy?config=file%3A%2Fvar%2Ffolders%2Fkt...". More readable it says "deploy?config=file:/var/folders/kt"
Probably Netbeans fails to cleanup this temporary directory and therefore uses old deployment files. Removing this temporary directory by 'rm -r /var/folders/kt' solves the issue.

Thanks Christophe for the quick replies and helping me out !

Cheers,

Peter
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You've solved most of it yourself Good to hear everything's ok now.
Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 22
Hmmmm... getting from the frying-pan into the fire now...

The klachtview.jsp is opened successfully now and and after submitting the klachSuccesView.jsp is opened.
The request handling is done by the KlachtController.class (when changing the value in setSuccessView the view fails to load).

But when i set the in the ModelAndView "melding" to a static value it is not shown in the page.
For quick and dirty debugging in Eclipse i always used System.out.println or Log statements to quickly print variables etc. Is there such a way in Netbeans when using Spring ?
Currently i cannot find any output generated in this class using System.out.println. I also want to double check if the Klacht bean is filled correclty with the data entered in the form.



Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 22
I am getting better at this

I had imported the wrong (java.net.BindException) class instead of org.springframework.validation.BindException.


 
Don't get me started about those stupid light bulbs.
 
subject: Getting a headage..... Cannot find class [...] for bean with name '...' defined in ServletContext re
 
Similar Threads
Spring MVC - Url Handling Problem
How to access application-context beans in dispatcher-servlet.xml
first app
problem while loading the welcome page
How dispatcher-servlet.xml works