DuplicateKey exception - spring

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.

Related

SpringBoot 2.6.7 Upgrade Throws Startup Error - Provider for javax.xml.stream.XMLOutputFactory cannot be found

I am unable to get past this error after upgrading SpringBoot from 2.5.10 - 2.6.7
I did find a version diff in jackson-dataformat-xml and raised an issue but they are confident there is no diff in jackson-dataformat-xml versions https://github.com/FasterXML/jackson-dataformat-xml/issues/521
Anyone faced this issue? Would appreciate if anyone could help
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163) ~[spring-boot-2.6.7.jar!/:2.6.7]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.6.7.jar!/:2.6.7]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is javax.xml.stream.FactoryConfigurationError: Provider for javax.xml.stream.XMLOutputFactory cannot be found
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.19.jar!/:5.3.19]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is javax.xml.stream.FactoryConfigurationError: Provider for javax.xml.stream.XMLOutputFactory cannot be found
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.19.jar!/:5.3.19]
Caused by: javax.xml.stream.FactoryConfigurationError: Provider for javax.xml.stream.XMLOutputFactory cannot be found
at javax.xml.stream.FactoryFinder.find(Unknown Source) ~[?:?]
at javax.xml.stream.XMLOutputFactory.newFactory(Unknown Source) ~[?:?]
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:124) ~[jackson-dataformat-xml-2.13.2.jar!/:2.13.2]

Mule Migration from 3.8.4 to 3.9.2 jars related issue

Getting below issue while migration from 3.8.4 to 3.9.2 Mule runtime.
java.lang.NoClassDefFoundError: org/springframework/context/ResourceLoaderAware (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException)
I have spring spring-context-4.1.9.RELEASE.jar and all default jars in opt folder of Mule runtime.
ResourceLoaderAware class is in this spring-context-4.1.9.RELEASE.jar.
Any idea how do I resolve this issue.
Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name '_muleNotificationManager': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_muleTransactionManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.mule.api.transaction.TransactionManagerFactory org.mule.config.spring.factories.TransactionManagerFactoryBean.txManagerFactory; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in class path resource [CCModuleFlood-context.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/context/ResourceLoaderAware (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:49) ~[mule-core-3.9.2.jar:3.9.2]
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.9.2.jar:3.9.2]
at org.mule.context.DefaultMuleContextFactory$1.configure(DefaultMuleContextFactory.java:89) ~[mule-core-3.9.2.jar:3.9.2]
at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:222) ~[mule-core-3.9.2.jar:3.9.2]
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:81) ~[mule-core-3.9.2.jar:3.9.2]
at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:210) ~[mule-module-launcher-3.9.2.jar:3.9.2]
... 18 more
Error NoClassDefFoundError doesn't mean that it was not able to find the class, it means that there was some previous error loading the class. You need to find the previous error to identify the root cause.
It might that there are some incompatible versions in the classpath that caused the original error.

How to Solve DispatcherServlet Class not found Exception

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.

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.

No suitable driver exception while grail tomcat deployment

I have deployed a grails application into tomcat container but am getting No suitable driver exception: can any one help in solving this.
SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoader Listener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'h ibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationExc eption: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc:xxxx:oracle://xxxxx:1521;ServiceName=xxxx'>
at org.grails.datastore.gorm.plugin.support.PersistenceContextInterceptorAggregator.postProcessBeanFactory(PersistenceContextInterce ptorAggregator.groovy:104) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve refe rence to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframewo rk.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons .dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc:xxxx:oracle://xxxx :1521;xxxx=xxxx'
... 1 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init meth od failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exc eption is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc:in formatica:oracle://xxxx:1521;xxx=xxx'
... 1 more
Caused by: org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache .commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc:xxx:oracle://xxxx:1521;xxxx=xxxx'
... 1 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc: xxxx:oracle://xxxx:1521;xxxx=xxxx'
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
... 1 more Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:264)
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 3 more
May 30, 2013 7:31:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
May 30, 2013 7:31:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/Jarvis] startup failed due to previous errors
May 30, 2013 7:31:25 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
UPDATED for a dependency definition example
Add the following repository definition to your BuildConfig.groovy
mavenRepo "https://code.lds.org/nexus/content/groups/main-repo"
In your dependencies section the following should appear:
runtime 'com.oracle:ojdbc6:11.2.0.3'
A better way is to install manually the Oracle driver to your corporate Repository(Artifactory, Nexus, Archiva, file server, etc.)

Resources