Spring-MVC bean class cannot be found - java

In my build.xml, I set the attribute scr.dir:
<property name="src.dir" value="${backend.dir}/java-src/catw/src"/>
My dispatcher-servlet.xml:
<bean name="/welcome.htm" class="com.bamboo.catW3.business.impl.WelcomeController"/>
My view WEB-INF/jsp:
welcome.jsp
My controller:
com.bamboo.catW3.business.impl.WelcomeController.java
I run the project and show me this message:
org.springframework.beans.factory.CannotLoadBeanClassException:
Cannot find class [com.bamboo.catW3.business.impl.WelcomeController] for bean
with name '/welcome.htm' defined in ServletContext resource
[/WEB-INF/branch_try_htmlModulo-servlet.xml]; nested exception is
java.lang.ClassNotFoundException: com.bamboo.catW3.business.impl.WelcomeController
org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1076)
I don't know how to fix this error, can anyone help me please?

In your build, your output directory is not pointing to the correct location (as specified by the destdir attribute. A ClassNotFoundException means that the application looks for the compiled WelcomeController, but cannot find it. Usually web application expects compiled class files to be under:
/WEB-INF/classes
So make sure that you build output points to this directory. After a successful build, you should see:
/WEB-INF/classes/com/bamboo/catW3/business/impl/WelcomeController.class

Double check that the destdir attribute of your tag (or tag) in your ant build script is set to the correct class directory for your application server (ie: Tomcat). You could also just look for the class file in your build directory.

May be many of u r getting problem with springhelloworld project.I have recently faced that problem as from eclipse when i am running it,it's working fine..but from browser it is showing error like class not found exception.So,I have found solution for that...it is a problem of class file....
Solution:
Just put your classes folder from build/classes to your WEB-INF directory...and your problem will be solved...
I hope this will help you...

Related

java.lang.NoClassDefFoundError from websphere

I have a problem that I can't figure out.
Context :
was 7.0.0.19 version (with no preCompileJsp)
Caused by: java.lang.NoClassDefFoundError: org/apache/jsp/_xxx (wrong name: com/ibm/_jsp/_xxx) at java.lang.ClassLoader.defineClassImpl(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:275) at java.lang.ClassLoader.defineClass(ClassLoader.java:212) at com.ibm.ws.jsp.webcontainerext.JSPExtensionClassLoader.defClass(JSPExtensionClassLoader.java:181) at com.ibm.ws.jsp.webcontainerext.JSPExtensionClassLoader._loadClass(JSPExtensionClassLoader.java:133)
It's the only JSP that give problem, and only on a specific environment (no problem on the others environments with the same configuration) the xxx.class is well present in my profile/tmp directory with others jsp in the same directory (that all give no problem) and the filesystem is not full.
Tests
I did a copy of xxx.jsp to xxxNew.jsp in the same directory
I can access the xxxNew.jsp without any problem (so there is no coding problem)
So I did a mv from xxx.jsp to xxx1.jsp and had no problem to access the jsp new named
I deleted the xxx.class in the tmp directory
I did the mv back to the first name (xxx.jsp) and still get the error with a newly xxx.class in the tmp directory.
Is there a class cache anywhere in websphere that could explain this ? (no cachespec.xml for dynacache found in the war module).
Why Websphere try to find a class from the org.apache.jsp package and not from com.ibm._jsp ? (how the AS choose the mapping from the URL to the classes ?)
Thxs !
Make sure you are not including in your webapp classpath any JSP engine or other implementation of standard JSP libraries that might be incompatible with WebSphere's runtime. Also, once you delete all potentially incompatible jars, try deleting the generated classes from JSP compilation (which are under {WAS_HOME}/AppServer/profiles/{YOUR_PROFILE}/temp), so recompilation would be triggered and discard any stale .class generated with a previous classpath state.
It would be helpful if you posted the list of JARs in your app's classpath.
Try changing the web application class loading policy on the WAS console: PARENT_FIRST / PARENT_LAST.
this bug is due to websphere incorrect log : the original exception is not displayed.
You should check for instance if there is no missing jsp tag libraries in your page.
See https://www-01.ibm.com/support/docview.wss?uid=swg1PI09596
Regards.

Initial SessionFactory creation failed.java.lang.ClassFormatError

Error in Console:-
Initial SessionFactory creation failed.java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/transaction/SystemException
Hello
I am building a standalone Java Application with Main Method which connects to the database using Hibernate and writes to a file on C drive as well.
I have added all the libraries to the class path using Java Build Path configuration and user libraries. But I keep getting this error ...I have also added the javaee jar from the glassfish server libraries but that has also not solved the problem. I also have the jboss-transaction-api_1.1_spec-1.0.0.Final.Jar added to my class path.
Please advise as I am not using Maven as yet ???
Here are the jars in my build path-
-antlr
-c3p0
-commons-collections
-commons-logging
-commong-logging-api
-dom4j
-hibernate-c3p0
-hibernate-commons-annotation
-hibernate-core
-hibernate-entitymanager
-hibernate-envers
-hibernate-jpa
-javaee-api-6.0jar
-javaassist
-jboss-logging
-jboss-transaction-api
-jms
-log4j
-lucene-core
-MySQL-connector
-slf4j
-javaee.jar
Any help would be truly appreciated .. I am just lost on what is going on ?
I am sure you have 2 different versions for the same class. check your jars.

Failed to import bean definitions from URL location [classpath:applicationContext-core.xml]

I'm working on a java project with spring on eclipse using Maven, and running on a Tomcat server v6.0. Everything was working fine since yesterday morning.
Here his my problem : I'm building my project, I got a build success. Then I start my Tomcat server and got this error :
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:applicationContext- core.xml]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext-core.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext-core.xml] cannot be opened because it does not exist
I found out similar problem on some website but none of them give me a solution that worked for me.
It seems that eclipse isn't able to find applicationContext-core.xml when I'm doing this :
<import resource="classpath:applicationContext-core.xml" />
However, I do have the needed jar file nad-core-0.0.1-SNAPSHOT.jar in WEB-INF/lib containing applicationContext-core.xml.
I even tried to add it manually to the classpath but I was still having the same problem.
I keep on looking for a solution, when suddendly it work again once after restarting Eclipse and building while Eclipse was still updating indexes and my project was having this strange status Hg status pending instead of default. Surprised by this result I decide to build again my project after restarting Eclipse and I got the error again and I enable to make it work again. It's quite annoying...
This looks to be a really random problem.
Thanks a lot for your help :)
As you've not specified you web application structure. I assume you've a simple web application at hand with the following structures
webapp
WEB-INF/classes/applicationContext.xml
WEB-INF/lib/nad-core-0.0.1-SNAPSHOT.jar/applicationContext-core.xml
Application context.xml refers to the applicationContext-core.xml file using the import tag. I did encounter a similar situation in my web application, here're the check lists that you should go through and may be one of them can apply to your situation.
Check the generated snapshot jar file for the applicationContext-core.xml file and make sure it is in the root directory of the jar. As silly as it sounds, this was the root cause of the issue I faced in my deployment.
Make sure your Maven Pom.xml file is configured to include this XML file from the resources folder. You can use the resource tags in the build phase of Maven to package them within the jar file itself.
You can try removing the import tag from application context.xml file and instead load both of them from Spring's webapplication context itself.
Add a context loader listener class from spring org.springframework.web.context.ContextLoaderListener
Add context-param contextConfigLocation with value classpath:applicationContext-core.xml,classpath:applicationContext.xml. Spring has the ability to dynamically sort out the dependencies before initiating the bean factory.
Hope this check list helps.
I get pretty much the same config, six years later, I got the same error.
I also restart Eclipse, and it solved the issue.

How to load Spring context xml from a jar file

I am running a Junit (SpringJUnit4ClassRunner) to access some spring beans in my integration test.
I need to load a few xml files via #ContextConfiguration, those files are deployed by a external approach to my Tomcat directly via a jar file. -- In other words, these files are in:
my_tomcat_home_path/webapps//WEB-INF/lib/external.jar
such as
my_tomcat_home_path/webapps//WEB-INF/lib/external.jar/a.suffix.xml
my_tomcat_home_path/webapps//WEB-INF/lib/external.jar/b.suffix.xml
...
I put Tomcat path into my eclipse classpath, then if I also include the that into my eclipse classpath, then the following code in my JUnit works
#ContextConfiguration(locations = {"classpath:*suffix.xml"})
However, if I don't put that into my eclipse classpath (because the jar file name may change from time to time), then my following code does NOT work (but Tomcat home "" is still in eclipse classpath):
#ContextConfiguration(locations = {"classpath:/webapps/<my_app>/WEB-INF/lib/external.jar/*suffix.xml"})
Could somebody please help me out?
Thanks a lot!!
Additional try -------------------------------
I tried to use the package path inside the jar, instead of using the external.jar itself. The the code looks like the following:
#ContextConfiguration(locations = {"classpath:/webapps/<my_app>/WEB-INF/lib/path_inside_the_external_jar/*suffix.xml"})
In this case, I no longer get "XML not found because file does not exist" problem. Instead, I get the following errors:
Caused by: java.io.FileNotFoundException: class path resource [webapps/my_app/WEB-INF/lib/path_inside_the_external_jar/] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:163)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.isJarResource(PathMatchingResourcePatternResolver.java:406)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:338)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:276)
at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1018)
at org.springframework.context.support.GenericApplicationContext.getResources(GenericApplicationContext.java:192)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:177)
... 23 more
Thanks a lot to Didxga's help!!
I tried to remove the "/webapps//WEB-INF/lib", and only leave the package path to the *suffix.xml (which are actually *.hbm.xml), then the #ContextConfiguration(locations looks like the following:
"classpath:/internal_path_within_jar/*hbm.xml"
at first, which is still not working.
Afterward, I tried the modify the classpath pattern and the following code ALMOST works
"classpath*:/internal_path_within_jar/*hbm.xml"
This time, since hbm.xml files are loaded, and I get the following error:
Caused by: java.net.UnknownHostException: hibernate.sourceforge.net
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:411)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:525)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:208)
at sun.net.www.http.HttpClient.New(HttpClient.java:291)
at sun.net.www.http.HttpClient.New(HttpClient.java:310)
However, I think now it is a different problem because it is hibernate DTD load problem... Maybe I should NOT load hbm.xml in this approach... I was forced to do so, because those hbm.xml files are generated during the deployment progress of my application and will only appear in the Tomcat's websapp/my_app/external.jar and NOwhere else...
Hmm, so I need work on that part... but how to include a jar into my eclipse path with changing name but a certain pattern? Such as *-dao.jar. OMG...
Anyway, I suppose the problem reported in this post should be resolved.
Thanks a lot, didxga!

NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService

While running the application I was getting the following errors.
java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService
AxisService class is in axis2-kernel-1.6.2.jar file. Some of the classes from this jar are working fine without any issues, but some classes are throwing NoClassDefFoundError from this jar file at runtime. AxisService class is present in axis2-kernel-1.6.2.jar, even it throws error.
This is working fine in local machine. But error getting in Oracle r12 server.I have already set the class path for the jar file.
I am Using Java version is 1.6 and Apache axis2.1.6.2.
Had the same issue. I had included only jars that I needed to compile the application.
When I included everything from \axis2-1.6.2\lib\ folder, this exception were gone.
I had a similar problem using Tomcat and Axis2 and after a week finding out the error I realized there was a axis configuration problem. especifically my aplication can't instantiate the class which accedded to persistence layer. I include this parameter line:
<parameter name="ServiceTCCL">composite</parameter>
in services.xml file which is used by axis2 to work.
For more information see the comments in http://wso2.com/node/1131

Categories