Spring boot application fails because it tries to load application.xml file - java

I am trying to add Spring boot to an existing and working Java web application, which uses Spring.
On starting the application such error is thrown:
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.xml'
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:476)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:465)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:386)
at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:225)
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:195)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:182)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:168)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.barclays.scp.eps.fullserve.application.Application.main(Application.java:12)
Caused by: java.util.InvalidPropertiesFormatException: org.xml.sax.SAXException: Invalid system identifier: http://java.sun.com/dtd/application_1_3.dtd
at java.util.XMLUtils.load(XMLUtils.java:59)
It seems that Spring boot is trying to load application.xml file as it's config file, though I haven't specified anywhere that such file is required and I had previously created Spring boot apps from scratch, no application.xml was required.
The project is quite big, it has many dependencies, maybe that could be caused by some of them?
I have tried adding application.xml to resources folder, a valid empty xml file - the main exception is still the same, though the cause of it is a bit different - Caused by: java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException: Premature end of file. This means the application.xml was read this time, but for some reason - incorrect.
What could be the issue here, why this application.xml is required at all? As far as I understand, such configuration file should not be required in Spring boot app.
Some info about project configuration - these Spring boot dependencies are added (Spring boot version 1.5.9.RELEASE):
compile('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
Main class launching the project is very basic (I know it will need more configuration, but one step at a time):
#SpringBootApplication
public class Application {
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
}
Any suggestions would be appreciated. Thank you!

The essayist is to create new Spring Boot project using https://start.spring.io/ and then migrate your code.
Everything else is much more work.

JDK: 1.8
Spring Boot: 2.1.4-RELEASE
#Adomas I met this situation just now. The reason is that I have a dependency jar which includes the file named 'application.xml' in the classpath.
After I remove this file 'application.xml' from this dependency jar, I had solved this problem.
22:20:52.866 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.xml'
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:556)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:502)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:469)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:450)
at java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:449)
at java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:446)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:334)
at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:209)
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:192)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:179)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.xxx.Application.main(Application.java:16)
Caused by: java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 33; 文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"。
at sun.util.xml.PlatformXmlPropertiesProvider.load(PlatformXmlPropertiesProvider.java:80)
at java.util.Properties$XmlSupport.load(Properties.java:1201)
at java.util.Properties.loadFromXML(Properties.java:881)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:137)
at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:122)
at org.springframework.boot.env.PropertiesPropertySourceLoader.loadProperties(PropertiesPropertySourceLoader.java:59)
at org.springframework.boot.env.PropertiesPropertySourceLoader.load(PropertiesPropertySourceLoader.java:47)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:574)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:528)
... 23 common frames omitted
Caused by: org.xml.sax.SAXParseException: 文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"。
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(XMLDTDValidator.java:1599)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1877)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:742)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1359)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1289)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3132)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:852)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
at sun.util.xml.PlatformXmlPropertiesProvider.getLoadingDoc(PlatformXmlPropertiesProvider.java:106)
at sun.util.xml.PlatformXmlPropertiesProvider.load(PlatformXmlPropertiesProvider.java:78)
... 31 common frames omitted
Process finished with exit code 1

The issue was caused by a dependency, which had application.xml in it's resources. In my case that was a legacy dependency and it was not used anywhere so the fix was just to remove it. In case that dependency was required, the solution would probably be to somehow exclude that application.xml loading as Spring boot config file.

I had issue with 1.5.9.RELEASE version
Error: Could not find or load main class ... in Spring Boot 1.5.9 version but not in 1.4.7
I currently use the 1.4.7.RELEASE. I would suggest you to try to update your spring dependency to this version
parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Spring Boot try to load "application.xml", "application.properties" and "application.yml" at "classpath:/". If you want to override the "application.xml", you need to use a valid xml. Like:
<?xml version='1.0' encoding="UTF-8" standalone = "yes"?>
<!DOCTYPE dummy [ <!ELEMENT dummy (dummy?) > ]>
<dummy><dummy></dummy></dummy>

Related

Spring Boot: "Logback configuration error detected" error

I am using aan external library (jar file from another project) and I added that Jar file (artifact) from Dependencies tab in the Project Structure ~ Modules section.
However, when I run my project, I get the following error. I am not sure what I am missing, but I think I also need to add some extra reference or library frokm the other project. Any idea?
Note that I created the artifact as mentioned on https://www.jetbrains.com/idea/guide/tutorials/hello-world/packaging-the-application/ . However, as that project is a Java8 project, I just added the module without starter class.
On the other hand, I added jar file to the project as mentioned on https://www.geeksforgeeks.org/how-to-add-external-jar-file-to-an-intellij-idea-project/.
Connected to the target VM, address: '127.0.0.1:59219', transport: 'socket'
Logging system failed to initialize using configuration from 'classpath:logback-default.xml'
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in biz.paluch.logging.gelf.logback.GelfLogbackAppender[GELF_UDP] - Unknown GELF server hostname:udp:LOG_ENDPOINT_IP_IS_UNDEFINED java.net.UnknownHostException: LOG_ENDPOINT_IP_IS_UNDEFINED: nodename nor servname provided, or not known
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:316)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:282)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:332)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
at nl.gerimedica.documents.GmDocumentsApplication.main(DemoApplication.java:16)
2022-10-03 11:06:42.723 ERROR 21530 --- [ main] o.s.boot.SpringApplication : Application run failed

Gradle not including one dependency when creating the artifact

I am using Gradle in an IntelliJ project to manage dependencies in a Spring project to provide REST web services. As long as I run the project in the IDE it works fine, but if I execute the java -jar artifact.jar command it cannot start. The following error is printed
13:42:47.338 [main] WARN org.springframework.boot.SpringApplication - Unable to close ApplicationContext
java.lang.IllegalStateException: Failed to introspect Class [com.(...).web_services.JmsConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#2cdf8d8a]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358)
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:747)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:746)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:685)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:656)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1670)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:667)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:659)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1300)
at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:914)
at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:902)
at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:889)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:830)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:349)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
at com.(...).web_services.WebServicesApplication.main(WebServicesApplication.java:10)
Caused by: java.lang.NoClassDefFoundError: javax/jms/ConnectionFactory
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.jms.ConnectionFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 25 common frames omitted
I suppose the javax.jms.ConnectionFactory class comes with the Spring ActiveMQ package, and I already tried to update Gradle manually but that did not solve the problem. Also importing javax.jms.ConnectionFactory in the JMS class did not help. Any clue?
The first attempt was to create a fat jar using the following custom gradle task (as suggested by #MatteoNNZ following this guide).
task customFatJar(type: Jar) {
manifest {
attributes 'Main-Class': '<myPackage>.<myMainClass>'
}
baseName = 'all-in-one-jar'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
However, as this didn't work, I ran the predefined gradle task buildDependents that created a working .jar in the build/libs folder.

java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.synchronization

While deploying application on Tomcat 8.0.36 I am getting following exception
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'eventsDAOImpl' Post-processing of merged bean
definition failed; nested exception is java.lang.NoSuchMethodError:
javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at
org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at
org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:940)
at
org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1816)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748) Caused by:
java.lang.NoSuchMethodError:
javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;
at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.(PersistenceAnnotationBeanPostProcessor.java:653)
at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.lambda$buildPersistenceMetadata$0(PersistenceAnnotationBeanPostProcessor.java:416)
at
org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:693)
at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:410)
at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:394)
at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:332)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1015)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
... 24 more
I am using eclipselink version 2.5.2 and added following jars in the lib folder of tomcat
eclipselink-2.5.2.jar
javax.persistence-api-2.2.jar
ojdbc6-12.1.0.1.jar
dependencies.gradle is as follows
compile (
'org.aspectj:aspectjrt:1.8.4',
'org.aspectj:aspectjweaver:1.8.4',
'org.springframework:spring-aspects:5.0.0.RELEASE',
'org.springframework:spring-jdbc:5.0.0.RELEASE',
'org.springframework:spring-jms:5.0.0.RELEASE',
'org.springframework:spring-orm:5.0.0.RELEASE',
'org.springframework:spring-oxm:5.0.0.RELEASE',
'org.springframework:spring-web:5.0.0.RELEASE',
'org.springframework:spring-webmvc:5.0.0.RELEASE',
'org.springframework:spring-instrument-tomcat:4.0.9.RELEASE'
}
provided (
'com.oracle:ojdbc6:12.1.0.1',
'org.eclipse.persistence:eclipselink:2.5.2'
)
Edit 1 : Same application is running fine on Tomcat 9 but giving above exception while deploying on Tomcat 8
Edit 2 : After doing some research I found out that Tomcat 8 is loading PersistenceContext class from annotations-api.jar located in TOMCAT_HOME\lib folder instead of javax.persistence-api-2.2.jar and PersistenceContext class available in annotations-api.jar does not contain synchronization method as follows.
package javax.persistence;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
#Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
#Retention(RetentionPolicy.RUNTIME)
public #interface PersistenceContext {
String name() default "";
String unitName() default "";
PersistenceContextType type() default PersistenceContextType.TRANSACTION;
PersistenceProperty[] properties() default {};
}
How to give preference in Tomcat 8 such that Tomcat 8 will load PersistenceContext class from javax.persistence-api-2.2.jar instead of annotations-api.jar
may be you are having conflicts in your spring data dependency version One is vesion1 (or replication of two same jar you can say)another is version2 Please remove older version dependency either version one or version two from pom.xml or from build path jar
OR
may be there is no Spring data jar or dependency over there please kindly add it.
org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Finals delivers an OLD version of javax.persistance that lack of that API PersitanceContext().synchronization()
Solution: add java.persistence:javax.persistence-api:2.2 BEFORE hibernate-jpa-2.0-api in the pom.xml
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
No idea about gradle, but at least you can try.
I see PersistenceContext.class with the synchronization() method in javax.persistence-api-2.2.jar. It looks like Apache has removed PersistenceContext (along with other classes) from annotations-api.jar as of Tomcat 7 which means it can't be loading this class from the Tomcat provided jar. Perhaps you have a another jar in your application that has an old version of PersistenceContext in it?

Logback upgrade from 1.1.11 to 1.3.0-alpha4 in Spring boot-1.5.8 application

Spring boot 1.5.8 by default providing logback-1.1.11 version.
I am trying to upgrade the logback version from 1.1.11 to 1.3.0-alpha4 and added the below two properties in pom.
<slf4j.version>1.8.0-beta4</slf4j.version>
<logback.version>1.3.0-alpha4</logback.version>
Getting the below exception when i try to run the application.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:273)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:98)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:230)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:209)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:292)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.anthem.acmp.service.UMIDALServiceApplication.main(UMIDALServiceApplication.java:25)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 14 more
I have found that the logback-classic-1.1.11.jar contains a package org.slf4j.impl which has the class StaticLoggerBinder, which is not available in logback-classic-1.3.0-alpha4 and causing this issue.
Logback 1.3 and SLF4J 1.8 contain breaking API changes when compared with their 1.2 and 1.7 versions respectively. At the time of writing, Spring Boot is not compatible with the new API. There's an issue that is tracking support of the new versions. It won't be tackled until the projects have stabilised and are no longer in alpha or beta.
I was able to use logback 1.3.0-alpha4 when I copied the StaticLoggerBinder from version 1.2 into my project. (Create a new StaticLoggerBinder.java in a new package org.slf4j.impl and paste the whole file.)

Maven: wrong Hibernate version?

I am encounting bug which is supposed to be fixed: isMember on #ElementCollection throws QuerySyntaxException: unexpected end of subtree
I googled about this issue and found ticket HHH-5799 and HHH-5209 where its claimed to be resolved in Hibernate 4.1.8, 4.3.0.Beta1.
I am trying to query for ProductType by one of its barcodes.
My entity looks like this:
#Entity
#XmlRootElement
public class ProductType implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue
private Long id;
#NotNull
#ElementCollection
private List<String> barcodes = new LinkedList<String>();
... getters+setters
}
I am using criteria api to query for product type by barcode using this code:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ProductType> c = cb.createQuery(ProductType.class);
Root<ProductType> f = c.from(ProductType.class);
c.select(f).where(cb.isMember(barcode, f.get(ProductType_.barcodes)));
TypedQuery<ProductType> query = em.createQuery(c);
return query.getSingleResult();
I made a simple test:
#Test
public void testProductTypeWithMultipleBarcodes()
{
ProductType type = new ProductType();
List<String> barcodes = new LinkedList<String>();
barcodes.add("1234561");
barcodes.add("1234562");
barcodes.add("1234563");
type.setBarcodes(barcodes);
em.persist(type);
em.flush();
assertEquals(type, productRepository.findProductTypeByBarcode("1234561"));
assertEquals(type, productRepository.findProductTypeByBarcode("1234562"));
assertEquals(type, productRepository.findProductTypeByBarcode("1234563"));
}
But I am getting org.hibernate.hql.internal.ast.QuerySyntaxException:
Caused by: org.jboss.arquillian.test.spi.ArquillianProxyException: org.hibernate.hql.internal.ast.QuerySyntaxException : unexpected end of subtree [select generatedAlias0 from cz.nuc.skladnik.storagecycle.product.ProductType as generatedAlias0 where :param0 member of generatedAlias0.barcodes] [Proxied because : Original exception not deserilizable, ClassNotFoundException]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.generate(QueryTranslatorImpl.java:238)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:214)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:192)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1537)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:487)
Before exception I see:
00:40:44,965 ERROR [org.hibernate.hql.internal.ast.ErrorCounter] (http--0_0_0_0_0_0_0_0-8080-1) <AST>:0:0: unexpected end of subtree: <AST>:0:0: unexpected end of subtree
at org.hibernate.hql.internal.antlr.SqlGeneratorBase.selectClause(SqlGeneratorBase.java:490) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
mentioning hibernate-core-4.0.1.Final. So I've tried to add dependency on hibernate-core in my pom with no result:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.1.Final</version>
</dependency>
Full pom.xml is here: http://pastebin.com/8U30fPpn
I think that hibernate-core-4.0.1.Final is dragged in by some other dependency. Is this source of my problem? And if yes is there any way to find out what dependency is the black sheep?
My container is JBoss 7.1.1 and I am using Arquillian for tests. As IDE I use IntelliJ Idea 13.
mvn dependency:tree: http://pastebin.com/k4YM1DpY
UPDATE: I found out that hibernate 4.0.1 was dragged in by JBoss server itself. So I tried to ugrade Hibernate using this Updating the Hibernate 4.x jars to a different Hibernate 4.x version
However after doing this I am getting NoClassDefFoundError: org/jboss/as/jpa/hibernate4/JBossAppServerJtaPlatform.
00:18:36,088 ERROR [org.jboss.as.controller.management-operation] JBAS014612: Operation ("parallel-extension-add") failed - address: ([]): java.lang.RuntimeException: JBAS014670: Failed initializing module org.jboss.as.jpa
at org.jboss.as.controller.extension.ParallelExtensionAddHandler$1.execute(ParallelExtensionAddHandler.java:99) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:385) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:272) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:200) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:149) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:190) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.ServerService.boot(ServerService.java:291) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.ServerService.boot(ServerService.java:266) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
Caused by: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org/jboss/as/jpa/hibernate4/JBossAppServerJtaPlatform
at java.util.concurrent.FutureTask.report(FutureTask.java:122) [rt.jar:1.7.0_51]
at java.util.concurrent.FutureTask.get(FutureTask.java:188) [rt.jar:1.7.0_51]
at org.jboss.as.controller.extension.ParallelExtensionAddHandler$1.execute(ParallelExtensionAddHandler.java:91) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
... 9 more
Caused by: java.lang.NoClassDefFoundError: org/jboss/as/jpa/hibernate4/JBossAppServerJtaPlatform
at org.jboss.as.jpa.hibernate4.HibernatePersistenceProviderAdaptor.injectJtaManager(HibernatePersistenceProviderAdaptor.java:59)
at org.jboss.as.jpa.processor.PersistenceProviderAdaptorLoader.loadPersistenceAdapterModule(PersistenceProviderAdaptorLoader.java:112)
at org.jboss.as.jpa.subsystem.JPAExtension.initialize(JPAExtension.java:118)
at org.jboss.as.controller.extension.ExtensionAddHandler.initializeExtension(ExtensionAddHandler.java:88) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.extension.ParallelExtensionAddHandler$ExtensionInitializeTask.call(ParallelExtensionAddHandler.java:127) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.extension.ParallelExtensionAddHandler$ExtensionInitializeTask.call(ParallelExtensionAddHandler.java:113) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.0.0.GA.jar:2.0.0.GA]
Caused by: java.lang.ClassNotFoundException: org.jboss.as.jpa.hibernate4.JBossAppServerJtaPlatform from [Module "org.jboss.as.jpa.hibernate:4" from local module loader #4e66ae7 (roots: d:\Programy\jboss-as-7.1.1.Final\modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
... 11 more
If you are somehow pulling in two org.hibernate:hibernate-core artifacts, dependency mediation should kick in and choose one. And there's no sign that you're pulling in two Hibernate artifacts with different coordinates from your dependency:tree output. So it sounds more like a misconfigured project than JAR hell per se, i.e. where you're pulling in conflicting libraries. If you want to be completely sure, though, check for duplicate files in your classpath using
mvn com.ning.maven.plugins:maven-duplicate-finder-plugin:1.0.4:check
which is a good JAR hell plugin.
Your POM file and dependency:tree output is showing your JBoss and Hibernate versions as RELEASE. I don't know if that's a JBoss thing, but it's unclear to me what version RELEASE corresponds to. You should try specifying versions in your dependency management section and seeing if the problem persists, e.g.
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.4.Final</version>
</dependency>
</dependencies>
</dependencyManagement>
...
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
</dependencies>
This has the advantage that you fix the version of the dependency for your whole project, including transitive dependencies, instead of hoping dependency mediation picks the right one.
By the way, a simpler way to get what you need out of dependency:tree is to filter, in your case using
mvn dependency:tree -Dincludes=:*hibernate*::
Try to run this command in the same directory as the pom.xml:
mvn dependency:tree -Ddetail=true -Dincludes=org.hibernate:hibernate-core
This will give you the dependency tree of not only the hibernate-core that was chosen, but other versions dependencies that altough present, where not chosen because some other dependency took precendence.
When in doubt which transitive dependency to choose, maven applies the following rules:
the dependency that is the closest to the pom.xml project wins. for example if one version is two levels away in the tree and another 1 level away, the one 1 level away wins.
if all dependencies are at the same level of distance from the pom.xml artifact, the one that shows up first on the pom wins.
The solution for this problem is to see with the comand above everyone that is requiring hibernate-core, decide which version you want and add the proper exclusions.
EDIT: The problem is that JBoss 7 is an EJB container that includes JPA, and the JPA on the server is interfering with the JPA on the WAR. This is because by default JBoss 7 works in 'server first' mode, where it will fetch libraries first from the server and only if they don't exist from the application.
You can change this to 'server last', where the jars on your application always take precedence. This can be done by setting java2ParentDelegation=false in file jboss-app.xml or jboss-web.xml - see also this answer.
You can also turn off server modules one by one, but this is more error prone.
For that, create a file in src/main/resources/META-INF named jboss-deployment-structure.xml, and there turn off the hibernate/JPA modules on the server:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.hibernate" />
<module name="org.jboss.as.jpa" />
<module name="org.jboss.as.jpa.hibernate" />
...
</exclusions>
</deployment>
</jboss-deployment-structure>

Categories