Compilation Failure : cannot access LoggingEventAware [ERROR] class file for org.slf4j.spi.LoggingEventAware not found on mvn clean install -U - spring-boot

I have upgraded the spring boot version from 2.3.5 to 2.7.5 , resolved most of the dependency versions. But when i do the maven clean install , i received the compilation failure error : cannot access LoggingEventAware
[ERROR] class file for org.slf4j.spi.LoggingEventAware not found
But i do not see any error in the java file - LoggingConfiguration.java.
When i just do reload of project to resolve all the dependencies - it gives error for maven plugin : Cannot resolve plugin org.apache.maven.plugins:maven-release-plugin:3.1.1
I am not sure what is the issue. I have tried to restart IntelliJ after invalidate cache and also cleared the .m2 repository .Nothing helps. Please suggest your inputs how to resolve the same.
Here is the sample pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-release-plugin.version>3.1.1</maven-release-plugin.version>
<maven-scm-provider-gitexe.version>1.9.5</maven-scm-provider-gitexe.version>
<junit.platform.version>4.13.0</junit.platform.version>
<logback-json-classic>0.1.5</logback-json-classic>
<logback-jackson.version>0.1.5</logback-jackson.version>
</properties>
</project> ```

While updating a project to Spring Boot 3.0.1, I came across the same issue.
Here is what worked for me:
Exclude logback-classic sub-dependency of spring-boot-starter-web.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
Add an earlier dependency of logback with version 1.2.11
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>

Related

How to attach Spring source for java 11

I am having a difficult time attaching Spring 5.3.x source code in eclipse.
I tried multiple ways one of them was to add a source to Java build path. However, I am not able to find the spring 5.3.x source code itself.
I have searched the official spring site - https://spring.io/blog/2018/10/30/spring-boot-2-1-0
on git too https://github.com/spring-projects
none of them has source code.
Another was to Right-click on the project -> maven -> Download Sources. It started updating the project however I still don't see the source code.
Can anyone help me solve this?
Your current java runtime in eclipse seems to be jdk8.
Go to Eclipse -> Preferences -> Java -> Installed JREs and switch to JDK11.
Then delete the project and reimport it again.
There might be some other issues in your project, after you switch to JDK11, but in this case I would need more information, including your pom.xml.
Also, check your project outside the eclipse, with command-line: "mvn clean install". Make sure that it compiles successfully, before importing it to eclipse. Make sure your JAVA_HOME points to JDK11
Here is the example of pom.xml for JDK11 Spring Boot 2.4.2 project. Compare it with your own pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>skyglass</groupId>
<artifactId>notepad</artifactId>
<version>1.1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>notepad</name>
<description>Notepad demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
.....
If nothing else helps, try to clean your local maven repository.
Deleting folder m2/repository/org/springframework should be enough

Spring project error using thymeleaf, Compilation failure. How can I fix this?

I'm pretty new at Spring framework, and I try to start a project for practice.
But I have an error and I have no idea how to fix this.
I've created a new Spring project in IntelliJ Idea, with Spring Initializr option (In Intellij, not with start.spring.io ). I added only 2 dependedncies for start (Web and Thymeleaf), but it throws error for Thymeleaf dependency if i run it with
'mvn spring-boot:run' command.
My spring project is "empty" , I have no controllers, beans, jpa entites, etc.. but it i think it shound run in this way too. I just wanted to make sure if it works if I run it.
If I create a same project, without Thymeleaf dependency (only Web dependency), it starts correctly on localhost.
I'm using Java 9.0.4 and Apache Maven 3.5.3
My error log
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo_thymeleaf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo_thymeleaf</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I solved it with deleting the whole C\Users\user.m2 directory.
After then with 'mvn spring-boot:run' it started successfully on localhost.
But I've got one more question:
When I run it, at terminal there are a couple of Warning messages.
Spring application runs anyway, but is there something to do with these messages?
Warning messages during Spring application run.

Spring Boot project in IntelliJ IDEA stops working after reboot

This is probably a newbie question, but I am not able to sort things out.
I've created a Spring Boot JAR-based Maven project using the Spring Initializr interface in IntelliJ IDEA. Its dependencies on Web and JDBC; an embedded instance of Tomcat is used to run the project.
I also have a couple of other Maven dependencies I add without problems from the relevant dialog; I also manually add the Apache Phoenix thin client JAR, that includes a copy of Logback (I am not able to get their Maven repository to work, but I don't think this is relevant to this question).
I am able to run the project flawlessly; after a system reboot (I am on Windows), a cascade of errors follows. First and foremost an exception signaling a conflict between Logback comes:
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from [...]). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory.
I would not like to alter the Phoenix client JAR; I am able to follow the instructions to replace the Spring dependency on Logback with another logger (log4j2 for example), but then the embedded Tomcat fails to create the container.
To get back to work, I have to recreate the project from scratch.
Could you please point me in the right direction to pinpoint the actual problem? Thank you.
Post scriptum: I am attaching the content of my pom.xml, apart from some potentially identifying information.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[RETRACTED]</groupId>
<artifactId>[RETRACTED]</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>[RETRACTED]</name>
<description>[RETRACTED]</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Firstly, rather than adding the apache phoenix client (or any other dependencies) manually you should add them to your maven pom.xml, so maven resolves the dependency at build time. If your project has dependencies which maven is failing to resolve this is a separate issue which you need to resolve, but adding them manually is bad practice for a number of reasons.
Once you have added the phoenix client as a dependency, you need to explicitly exclude slf4j-log4j12 and log4j as part of the dependency declaration. The XML should look something like this:
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.13.1-HBase-1.3</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
The reason these need excluded is that they are conflicting with the versions bundled in the spring-boot project
Hopefully this will sort your problem.

Hive 0.14 UDF Maven Project Missing Dependencies

I was trying to set up a Maven project that will contain user defined functions (UDFs) that I'd like to use in my Hive queries. I started with a Maven project containing no source files, and the following POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>exp</groupId>
<artifactId>HiveUdfTestProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>0.14.0</version>
</dependency>
</dependencies>
</project>
When I tried to build the project, I get the following error:
Failed to execute goal on project HiveUdfTestProject: Could not
resolve dependencies for project
exp:HiveUdfTestProject:jar:1.0-SNAPSHOT: The following artifacts could
not be resolved:
org.apache.calcite:calcite-core:jar:0.9.2-incubating-SNAPSHOT,
org.apache.calcite:calcite-avatica:jar:0.9.2-incubating-SNAPSHOT:
Could not find artifact
org.apache.calcite:calcite-core:jar:0.9.2-incubating-SNAPSHOT -> [Help
1]
I found the calcite-core-incubating jar in the maven central repository (but not the incubating-snapshot version) required by the hive-exec 0.14.0 dependency.
Adding the calcite-core from maven central got rid of the original error, and introduced a new missing dependency "pentaho-aggdesigner-algorithm" which I found on ConJars.
Adding the conjars repo and the pentaho dependency made a new missing dependency appear "org.apache.calcite:calcite-avatica:jar:0.9.2-incubating-SNAPSHOT" whose incubating (but not snapshot) dependency was available in the maven central repo.
Adding the calcite-avatica dependency to the POM made the empty project build successfully at last.
Here is the final POM needed to make a project intended for Hive UDFs build:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>exp</groupId>
<artifactId>HiveUdfTestProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>conjars.org</id>
<url>http://conjars.org/repo</url>
</repository>
</repositories>
<dependencies>
<!-- From Maven Central -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>0.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>0.9.2-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-avatica</artifactId>
<version>0.9.2-incubating</version>
</dependency>
<!-- From conjars -->
<dependency>
<groupId>org.pentaho</groupId>
<artifactId>pentaho-aggdesigner-algorithm</artifactId>
<version>5.1.3-jhyde</version>
</dependency>
</dependencies>
</project>
Once the empty project built, I tried integrating the POM settings into a larger existing Maven project and saw errors about calcite-core specifically looking for the snapshot version. To get past this, I changed the hive-exec dependency to look like this:
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>0.14.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.calcite</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
I explicitly included the calcite-core and calcite-avatica projects as dependencies, and my project (which also includes the Hive 14 dependencies), no longer failed with the 'artifacts could not be resolved error'
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>1.0.0-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-avatica</artifactId>
<version>1.0.0-incubating</version>
</dependency>
From what I can tell, this is an open issue with Hive 14. See https://issues.apache.org/jira/browse/HIVE-8906 for more info.
I've resolved the same issue by adding below dependencies to /ql/pom.xml
org.pentaho
pentaho-aggdesigner-algorithm
5.1.3-jhyde
<dependency>
<groupId>eigenbase</groupId>
<artifactId>eigenbase-properties</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>net.hydromatic</groupId>
<artifactId>linq4j</artifactId>
<version>0.4</version>
</dependency>
and below repository to /pom.xml under positories
<repository>
<id>conjars</id>
<name>Concurrent Conjars repository</name>
<url>http://conjars.org/repo</url>
<layout>default</layout>
</repository>

Exercise - Maven by Example book

I'm trying to study Maven, and so I created a simple web application as provided on the book "Maven by Example", and in that applicaton I have the simple-weather having simple-model as a dependency, inside the simple-parent maven project.
I just copied the pom.xml (making just adjustments to the hibernate artifact version), and when I run "mvn install" on the "simple-model", it builds ok, but when I run "mvn install" on the "simple-weather" it doesn't build ok because it says it doesn't find the packages related to the simple-model dependency.
NOTE: If I create two eclipse projects and relate simple-model" it compiles ok, so there is no issue related to the projects compilation.
See both pom.xml. I suppose the issue is on the pom.xml, but I have no idea of what to do. I already tried to fix in many ways, but got no success at all.
I already copied even the group and artifact id from the simple-model to the simple-weather to guarantee it was not a typing issue. :-(
//simple-model -> pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multispring</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-model</artifactId>
<packaging>jar</packaging>
<name>Simple Object Model</name>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
</dependency>
</dependencies>
</project>
//simple-weather -> pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multispring</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-weather</artifactId>
<packaging>jar</packaging>
<name>Simple Weather API</name>
<dependencies>
<dependency>
<groupId>org.sonatype.mavenbook.multispring</groupId>
<artifactId>simple-model</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
See the error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.
3.2:testCompile (default-testCompile) on project simple-weather: Compilation fai
lure: Compilation failure:
[ERROR] \mavenTest\ch-multi-spring\simple-parent\simple-weather\src\test\java\or
g\sonatype\mavenbook\weather\yahoo\YahooParserTest.java:[8,43] error: package or
g.sonatype.mavenbook.weather.model does not exist
Any assistance would be appreciated. Thank you in advance.
Is the source in simple-model actually correct?
Please note that Maven is not complaining for unresolved dependency. Dependencies seems correct and it is compilation error that it cannot find the package org.sonatype.mavenbook.weather.model. It is mostly because such package is available neither in the simple-web project itself, nor in its dependencies (i.e. simple-model).
Check the JAR created in simple-model to see if it contains correct content.

Resources