How to Solve DispatcherServlet Class not found Exception - spring

I am trying to run Hello world Spring MVC Program. But I am getting the following errors. I have tried so many times from different website, But I couldn't solve this Problem. So Please can anyone help me to solve this.
Apr 29, 2018 7:32:12 PM
org.springframework.web.context.ContextLoader
initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorldService' defined in file
[/home/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/spring-web-gradle-xml/WEB-INF/classes/com/mkyong/helloworld/service/HelloWorldService.class]:
Instantiation of bean failed; nested exception is
java.lang.NoClassDefFoundError:
ch/qos/logback/core/joran/spi/JoranException
INFO: Marking servlet spring as unavailable
Apr 29, 2018 7:32:12 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /SpringMVC-Hibernate threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:529)

Make sure that logback Jar is in your classpath.
You can go through this manual and configure your project accordingly.
In case you use a build tool, feel free to post your build configuration file here for a more detailed answer.

Related

Eclipse STS run Spring Boot locally with subprojects

I have the following project structure:
root project
|-- controller
|-- core
|-- widgets
|-- widgetA
|-- widgetB
These projects all get built into jars except controller. Then the jars are deployed to a class folder and controller uses context.xml to specify their location.
This all works great during deployment (except Tomcat's 'redeploy' doesn't redeploy, I suspect an issue with classloaders, but an unload/deploy works fine). However, we currently cannot run this locally in STS because the controller needs a bean from the 'widgets' project that the system can't locate.
The project begins fine when I execute the controller project as a Spring Boot App. It loads, and discovers the beans defined in the 'core' project. But for some reason the 'widgets' project is not scanned by Spring. Again, when this is deployed, Spring scans them all just fine (I assume because of the context.xml that defines the JarResources to load). But I just can't seem to figure out how to get STS to "see" the project.
Edit: For clarity, here is the error I am getting:
May 22, 2018 2:32:00 PM org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'Controller': Unsatisfied dependency expressed through field 'widgetMap'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.Map<java.lang.String, com.mycompany.project.widgets.WidgetInterface>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
System is shutting down
May 22, 2018 2:32:00 PM org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor shutdown
INFO: Shutting down ExecutorService 'getAsyncExecutor'
May 22, 2018 2:32:00 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service [Tomcat]
May 22, 2018 2:32:00 PM org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener logAutoConfigurationReport
INFO:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
May 22, 2018 2:32:00 PM org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter report
SEVERE:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field widgetMap in com.mycompany.project.controller.Controller required a bean of type 'com.mycompany.project.widgets.WidgetInterface' that could not be found.
Action:
Consider defining a bean of type 'com.mycompany.project.widgets.WidgetInterface' in your configuration.
I resolved the issue.
Turns out I was not adding the individual widgets to my build path, but only the 'widgets' class.
Because I was using an #Autowired Map object, I needed at least one of my WidgetInterface implementations on the build path. Since the widget implementation projects were not present, it could not properly instantiate the map, and was erroring out.

Spring Integration Exception

I am getting an exception in spring integration. Following is the snippet of my spring.xml file
<int-file:inbound-channel-adapter id=ïncomingFile" directory="file:${myapp.incomingFile.path}"prevent-duplicates="true"filename-regex="${filenameRegex}>
<int:poller id="poller"fixed-delay="5000"/>
</int-file:inbound-channeladapter>
Exception:
7 May 2014 13:52:17.903 [main] INFO App.main - Starting with the main application
May 17, 2014 1:52:18 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#2814a18d: startup date [Sat May 17 13:52:18 EDT 2014]; root of context hierarchy
May 17, 2014 1:52:18 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [file:./src/main/resources/spring//Spring-All-Module.xml]
May 17, 2014 1:52:18 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [file:src/main/resources/spring//filetracker.xml]
May 17, 2014 1:52:18 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from URL [jar:file:/C:/Users/sbhargava/.m2/repository/org/springframework/integration/spring-integration-core/4.0.0.RELEASE/spring-integration-core-4.0.0.RELEASE.jar!/META-INF/spring.integration.default.properties]
May 17, 2014 1:52:18 PM org.springframework.integration.config.IntegrationRegistrar registerHeaderChannelRegistry
INFO: No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
May 17, 2014 1:52:18 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [config/filetracker.prop]
May 17, 2014 1:52:18 PM org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor registerErrorChannel
INFO: No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
May 17, 2014 1:52:18 PM org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor registerTaskScheduler
INFO: No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
May 17, 2014 1:52:18 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from URL [jar:file:/C:/Users/sbhargava/.m2/repository/org/springframework/integration/spring-integration-core/4.0.0.RELEASE/spring-integration-core-4.0.0.RELEASE.jar!/META-INF/spring.integration.default.properties]
May 17, 2014 1:52:18 PM org.springframework.scheduling.concurrent.ExecutorConfigurationSupport initialize
INFO: Initializing ExecutorService 'taskScheduler'
May 17, 2014 1:52:18 PM org.springframework.scheduling.concurrent.ExecutorConfigurationSupport shutdown
INFO: Shutting down ExecutorService 'taskScheduler'
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incomingFiles.adapter': Cannot resolve reference to bean 'incomingFiles.adapter.source' while setting bean property 'source'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incomingFiles.adapter.source': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: org/springframework/integration/MessagingException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:681)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.queryutility.jefferies.fileutility.App.main(App.java:28)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incomingFiles.adapter.source': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: org/springframework/integration/MessagingException
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:151)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:252)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320)
... 15 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/integration/MessagingException
at org.springframework.integration.file.FileReadingMessageSource.<init>(FileReadingMessageSource.java:77)
at org.springframework.integration.file.FileReadingMessageSource.<init>(FileReadingMessageSource.java:96)
at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.initSource(FileReadingMessageSourceFactoryBean.java:128)
at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.getObject(FileReadingMessageSourceFactoryBean.java:98)
at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.getObject(FileReadingMessageSourceFactoryBean.java:36)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:144)
... 20 more
Caused by: java.lang.ClassNotFoundException: org.springframework.integration.MessagingException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 26 more
MessagingException has been moved to the spring-messaging module since Spring Framework 4.0 and Spring Integration 4.0.
If you see that exception, then you use an old version of some of Spring Integration modules. Might be ever spring-integration-file
Use Same version for spring-integration-core and spring-integration-ftp or spring-integration-file will help. It worked for me.

DuplicateKey exception

I am running a spring web application with MySQL database. I get the following error.
ec 09, 2013 6:33:31 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [login] in context with path [/Loginwithmysql] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/DuplicateKeyException] with root cause
java.lang.ClassNotFoundException: org.springframework.dao.DuplicateKeyException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
at org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator(JdbcAccessor.java:99)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:602)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
The class DuplicateKeyException is part of the spring-tx library. You will need to add it to your classpath. You can get it here.

Cannot find class [org.springframework.orm.hibernate.LocalSessionFactoryBean]

I have encounter a problem with spring hibernate, can some help me with this? I think I get all the library in my project:sping-orm ...
Jul 5, 2012 2:13:58 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#4e3eca90: startup date [Thu Jul 05 14:13:58 EDT 2012]; root of context hierarchy
Jul 5, 2012 2:13:58 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Jul 5, 2012 2:13:59 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#d576e70: defining beans [myDataSource,mySessionFactory,hibernateTemplate,expertiseDao]; root of factory hierarchy
Jul 5, 2012 2:13:59 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#d576e70: defining beans [myDataSource,mySessionFactory,hibernateTemplate,expertiseDao]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate.LocalSessionFactoryBean] for bean with name 'mySessionFactory' defined in class path resource [spring.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate.LocalSessionFactoryBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1262)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1331)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:897)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:566)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
at com.gs.project1.main.TestRun.main(TestRun.java:17)
Caused by: java.lang.ClassNotFoundException: org.springframework.orm.hibernate.LocalSessionFactoryBean
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:417)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1283)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1254)
... 9 more
Seems like the correct package name was not supplied. I did a quick search for the class LocalSessionFactoryBean and realized that its not available in the same package. Could be the difference in version of Spring framework with which this was built and the runtime library available.

How do you run Spring 2.5.6 sample apps in Jdeveloper 11g?

I am trying to run imageDB and jpetstore in JDeveloper 11g. It compiles fine, but it won't run, and the weblogic server throws errors. Does anyone know how to successfully run Spring 2.5.x sample applications in Jdeveloper 11g?
I get the following error when I try jpetstore sample.
Jul 27, 2009 5:03:20 PM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing
XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: Could not initialize class
org.springframework.aop.aspectj.AspectJExpressionPointcut
The problem occurs because of WebLogic Server Application Classloading.
You need the following weblogic.xml.
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
for more info: http://download.oracle.com/docs/cd/E13222_01/wls/docs92/programming/classloading.html

Resources