-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Elasticsearch starter forces use of Log4j2, breaking logging in apps that try to use Logback #10847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the sample. The application starts successfully, it's just some logging that's lost. That appears to be due to the fact that you have both Logback and Log4j2 on the classpath. Things work as expected if you exclude Log4j2: compile('org.springframework.boot:spring-boot-starter-data-elasticsearch') {
exclude group: 'org.apache.logging.log4j'
} I'm not sure why Spring Data Elasticsearch pulls in all of Log4j2 rather than just a logging API. That should either be changed in Spring Data Elasticsearch or we should consider adding some exclusions in our starter. @olivergierke @mp911de Can you please advise? |
That's a bug in the POM. Feel free to exclude in the starter for the upcoming milestone but we're gonna get this fixed with the next bugfix release for Kay. |
Confirmed! Thank You for clarification and help. Note: I'm trying to use new spring-data-elasticsearch v3.0.0.RELEASE in order to connect to ES 5.x. |
"Two cents" more on this topic :), as it seams not solved just by exclusion. Try to add ElasticSearch Configuration class (JavaConfig), e.g. @Configuration
public class ESConfig {
@Bean
public Client client() throws UnknownHostException {
TransportClient esClient = new PreBuiltTransportClient(Settings.EMPTY);
esClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));
return esClient;
}
public ElasticsearchOperations esTemplate() throws UnknownHostException {
return new ElasticsearchTemplate(client());
}
} Now, starting application will "complain" about missing log4j.
In order to help you debug this, please checkout GitRepo: Note: |
@staleks Can you post the full stack trace please. |
@philwebb sure, Here is complete DEBUG log, on application context loading: You can find project at: |
I guess that's the reason, the Log4j dependencies made it into the compile scope of Spring Data ES in the first place. I tried to remove the dependencies completely as we pull in Logback in the Spring Data builds during tests anyway but that causes the tests to fail with a similar exception. It looks like ES doesn't properly run without Log4j being used. |
I believe that can be avoided with a runtime dependency on @staleks For some reason that module is not part of Log4j2's bom (so Boot doesn't currently manage its version). However, you can align its version with the version of the log4j-api module (which Boot does manage) like this:
In summary, I think the long term fix for this is for Spring Data Elasticsearch to exclude any Log4j2 implementation dependencies and pull in |
I've opened LOG4J2-2093 to see if |
Thanks, Andy. I’ll proceed as suggested and ping you once the fix is available. |
@wilkinsona This change caused a test to fail in spring-cloud-gateway. See https://jenkins.spring.io/blue/organizations/jenkins/spring-cloud-gateway-2.0.x-ci/detail/spring-cloud-gateway-2.0.x-ci/1019/pipeline Adding the following exclusion to the pom fixed the error. Seems a bit bizarre to me:
|
It appears that the test failures are due to a bug in ModifiedClassPathRunner which is causing |
Adding changes you made to the boot version (excluding log4j jars) fixed the problem. |
Aah, I'd forgotten I'd had to do that. Sorry. Could have saved us all some cycles if my memory was a bit better… |
The reductions of the scope of the log4j dependencies for Spring Data Elasticsearch have now been applied to the Lovelace and Kay release train branches. Snapshots should be available shortly. |
I'm trying to run
spring-boot-starter-data-elasticsearch
in latest Milestone 2.0.0.M5.I've used project template generated from start.spring.io.
Here is the GitHub repo url: https://github.com/staleks/spring-boot-2.0.M5-ES
Run
$ ./gradlew clean build
$ ./gradlew bootRun
stale the process of loading application context.
Please check the attached image: https://github.com/staleks/spring-boot-2.0.M5-ES/blob/master/images/staled-bootRun-process.png
On the other hand, if I switch back to 1.5.8.RELEASE version
(GitHub repo url: https://github.com/staleks/spring-boot-1.5.8-ES)
Run
$ ./gradlew clean build
$ ./gradlew bootRun
application context is loaded, and web application is started.
Please check the attached image: https://github.com/staleks/spring-boot-1.5.8-ES/blob/master/images/bootRun-process.png
Can someone please verify this?
Thank You
The text was updated successfully, but these errors were encountered: