I want to customize springboot 2.6.8 elasticsearch dependency to elasticsearch 7.17.2, is this ok?
Based on springboot dependency versions, 2.6.8 is mapped to elasticsearch version 7.15.2.
But I want to changed it since elasticsearch version 7.15.2 has some deprecated functions.
How to do it?
the pom.xml I am using does not have spring-boot-starter-data-elasticsearch
and if I use it Maven cannot find it in:
<repositories>
<repository>
<id>shibboleth_repository</id>
<name>Shibboleth Maven Repository</name>
<url>https://build.shibboleth.net/nexus/content/repositories/releases/</url>
</repository>
</repositories>
<properties>
<java.version>17</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.8</version>
</parent>
<dependencies>
:
:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>
:
</dependencies>
I want to customize springboot 2.6.8 elasticsearch dependency to elasticsearch 7.17.2, is this ok?
One never knows until they try. The ElasticSearch version 7.17.2 contains backward-compatible changes 7.15.2, hence it should be ok.
How to do it?
Check the dependency trees:
spring-boot-starter-parent:2.6.8
spring-boot-starter-data-elasticsearch:2.6.8
spring-data-elasticsearch:4.3.4
org.elasticsearch.client:...:7.15.2
... and ...
spring-boot-starter-parent:2.7.0
spring-boot-starter-data-elasticsearch:2.7.7
spring-data-elasticsearch:4.4.0
org.elasticsearch.client:...:7.17.3
You might want either to update Spring Boot to 2.7.0 for full compatibility that imports transitive dependencies of ElasticSearch version 7.17.3 or override the versions: Exclude all the org.elasticsearch.client dependencies and import them as separate dependencies.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<exclusions>
<!-- repeat for all ElasticSearch dependencies -->
<exclusion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>...</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- repeat for all ElasticSearch dependencies -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>...</artifactId>
<version>7.17.2</version>
</dependency>
Related
I am using Spring Boot 2.7.2 to create a rest API that communicate with Filenet Content Engine using Filenet APIs and my pom file as follows :
<?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 https://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.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>storage</artifactId>
<version>0.0.1</version>
<name>storage</name>
<description>Storage API</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Filenet Jars -->
<dependency>
<groupId>Jace</groupId>
<artifactId>Jace</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>stax-api</groupId>
<artifactId>stax-api</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>xlxpScanner</groupId>
<artifactId>xlxpScanner</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>xlxpScannerUtils</groupId>
<artifactId>xlxpScannerUtils</artifactId>
<version>5.2.1</version>
</dependency>
<!-- End Of Filenet Jars -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<!--
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>MCI-maven</id>
<url>http://myhost/repository/maven-public/</url>
</repository>
</repositories>
</project>
The project compiles and starts up fine, but when trying to execute any filenet API I get a log4j error:
ClassNotFoundException: org.apache.log4j.Priority
That is because filenet APIs is using log4j1 classes.
The class is : com.filenet.apiimpl.util.BaseLogger.
The class imports are:
import com.filenet.api.exception.EngineRuntimeException;
import com.filenet.api.exception.ErrorLoggingLevel;
import com.filenet.api.util.UserContext;
import com.filenet.apiimpl.exception.ExceptionContext;
import java.util.Enumeration;
import org.apache.log4j.Category;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
The current solution is to add log4j 1.2.17 in pom file
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
When adding this the runtime exception disappears and everything works fine. But I only get the following warning on first time invoking filenet API:
log4j:WARN No appenders could be found for logger (filenet_error.api.com.filenet.apiimpl.util.ConfigValueLookup).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[Perf Log] perflog.dir=null not found, auditor disabled
[Perf Log] No interval found. Auditor disabled.
Is there any better solution to this scenario rather than adding old log4j dependency ?
According to your actual pom.xml file, following the transitive dependencies spring-boot-starter-web and spring-boot-starter, you will end using spring-boot-starter-logging and its different dependent libraries, mainly based on logback and slf4j.
As you indicated, the Filenet APIs use Log4j 1.x.
The support for that version of Log4j was removed with the release of Spring Boot 2.x.
As a consequence, by default, the library will not give you support for that logging library.
That is the reason why you are facing the ClassNotFoundException: org.apache.log4j.Priority error.
In my opinion the solution you applied based on the inclusion of the log4j dependency itself is not a bad solution. A word of caution though:
the library has different vulnerabilities.
it was declared end-of-life in August of 2015.
the solution has the drawback of requiring a different configuration for the library and probably different output artifacts in which the log traces should be written.
As an alternative, you could use the Log4j 1.x bridge provided by Slf4j:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
You can use the version 1.7.36 although it is managed by Spring Boot Starter Parent as well, so you don't need to provide a specific version for it.
Maybe there can be some caveats, some functionally used by the Filenet logger not implemented, but at first glance it seems to provide all the required stuff used by com.filenet.apiimpl.util.BaseLogger.
If that's the case, it will give you a better solution than using the log4j library, for the reasons explained, especially because it will allow you to integrate the Filenet loggers with your existing Spring Boot logging configuration and infrastructure.
Adding the following dependencies fixed my problem:
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '2.7.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
implementation group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.36'
I have the following dependency in my Maven project
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.2.jre8</version>
<!-- Exclude unused Azure dependencies -->
<exclusions>
<exclusion>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-keyvault</artifactId>
</exclusion>
<exclusion>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
</exclusion>
</exclusions>
</dependency>
I am using the newest non-preview mssql-jdbc release in Maven here
https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
However when I run mvn clean package my resulting war file has mssql-jdbc-6.1.0.jre7.jar in WEB-INF/lib instead of the expected mssql-jdbc-6.2.2.jre8.jar. I have tried clearing my local .m2 repository and repackaging but that did not help. It is worth noting that 6.1.0.jre7 is actually the oldest version out there, so my guess is that for some reason it cannot find the newest one and is reverting to the oldest? I'm stuck.
I encountered same problem, and I am using Spring Boot 1.5.x.
The root cause is: Spring Boot(1.5.x) specified the version of "6.1.0.jre7".
Solution is: specify your version in the main module which contains Spring boot Application.
Previous part of my dependencies:
Sub module 1:
<groupId>com.my.company</groupId>
<artifactId>sub-module1</artifactId>
<version>1.0</version>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.1.3.jre8-preview</version>
</dependency>
Main module, which contains Spring boot Application:
<dependency>
<groupId>com.my.company</groupId>
<artifactId>sub-module1</artifactId>
<version>1.0</version>
</dependency>
And I found Main module boot.jar included "mssql-jdbc-6.1.0.jre7.jar".
Finally I found the version is specified in "spring-boot-dependencies" which is the parent of "spring-boot-parent".
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.16.RELEASE</version>
<mssql-jdbc.version>6.1.0.jre7</mssql-jdbc.version>
Solution:
Specify the version in main module:
<dependency>
<groupId>com.my.company</groupId>
<artifactId>sub-module1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.1.3.jre8-preview</version>
</dependency>
Checked the result by mvn denpendency:tree, it's ok
This is my pom.xml
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
it.test
searchTest
0.0.1-SNAPSHOT
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M5</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Runtime, for Embedded Elasticsearch,
comment this if connect to external elastic search server-->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Package as an executable jar/war -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
When I start my project I have returned this stack trace:
[2017-12-15T13:36:15,670][WARN ][o.e.t.n.Netty4Transport ] [node1] exception caught on transport layer [org.elasticsearch.transport.netty4.NettyTcpChannel#7c08d374], closing connection
java.lang.IllegalStateException: Received message from unsupported version: [5.5.3] minimal compatible version is: [5.6.0]
at org.elasticsearch.transport.TcpTransport.ensureVersionCompatibility(TcpTransport.java:1428) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.transport.TcpTransport.messageReceived(TcpTransport.java:1375) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.channelRead(Netty4MessageChannelHandler.java:64) ~[transport-netty4-6.1.0.jar:6.1.0]
What I have to change in my pom to solve this incompatibility?
Thanks
Change the transport version to be the same as your elasticsearch instance
What is the version of your ElasticSearch, Maybe you can try to add this property in your pom like this.
<properties>
<elasticsearch.version>6.1.0</elasticsearch.version>
</properties>
I always find the Spring data elasticsearch matrix table useful for figuring out what compatible version to use.
To change version of ES from to a compatible version use the Spring Boot dedicated module to specify dependency versions. Add elasticsearch.version into your pom properties
<properties>
...
<elasticsearch.version>1.7.2</elasticsearch.version>
...
</properties>
i too was getting similar error but got resolved, before which i like to highlight my spring boot starter parent version which is 1.5.9.RELEASE, secondly i was using spring-boot-starter-data-elasticsearch artifact alone for spring boot elastic search and other artifacts can be removed, finally the phenomenal issue which you are receiving with the elastic search application which you have installed, try to download this version https://www.elastic.co/downloads/past-releases/elasticsearch-2-4-0 and try again....
I like to know if below is possible and how.
I was following a tutorial for spring boot and it was mentioned there we can have a parent dependency.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
And then define the dependencies without the version number.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
This will add the dependencies version 1.5.6.RELEASE of spring-boot-starter and spring-boot-starter-web in to the projects dependencies.
Just like that I want to find what is the <parent> code snippet for the following dependencies I need to add in to a new project.
Dependencies in <groupId>org.springframework</groupId>. I need to use the version 4.3.9.RELEASE.
spring-context
spring-jdbc
spring-test
Thanks!
If you are using Spring Boot then these three dependencies will be provided for you by the following starters:
spring-test will be provided by spring-boot-starter-test
spring-context will be provided by spring-boot-starter-data-jpa
spring-jdbc will be provided by spring-boot-starter-jdbc
So, with the following parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
... if you add these dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
... then you will get
spring-context
spring-jdbc
spring-test
However, Spring Boot 1.5.6.RELEASE depends on v4.3.10.RELEASE of those core Spring libraries not 4.3.9.RELEASE as suggested in your question. Typically, you would accept Spring's curation of dependencies so if Sping provides 4.3.10.RELEASE then either (a) you should use that version or (b) downgrade Spring Boot toa version which provides 4.3.9.RELEASE.
Read on for details on how to identify the correct starter for a given curated library ...
The spring-boot-starter-parent is a special starter that provides useful Maven defaults and a dependency-management section which defines numerous dependencies which you might want to use in your POM. These dependencies are often referred to as "curated" or "blessed" and since they are defined in a dependency-management section somewhere in the maven hierarchy you can refer to them in your POM without a version tag (i.e. they inherit the version from the dependency-management section entry.)
You can see the spring-boot-starter-parent POM here and peeking inside you can see that it references the spring-boot-dependencies POM here.
Looking at your question you mentioned that you can declare a dependency like so ...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
... this is because the spring-boot-dependencies POM declares the following:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${revision}</version>
</dependency>
So, the parent and the starters are just a means of wrapping up dependency declarations and making them easier for application developers to use. The Spring docs summarise this as:
Starters are a set of convenient dependency descriptors that you can include in your application. You get a one-stop shop for all the Spring and related technologies that you need without having to hunt through sample code and copy-paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access, include the spring-boot-starter-data-jpa dependency in your project.
However, this does not mean that all dependencies must be declared via parents or starters so, if you are not using Spring Boot then you can declare a dependency without using a parent or a starter and what you have described in your question (declaring dependencies on 3 core Spring libraries) can be safely covered by simply depending on those 3 libraries explicitly. For example, just add the following to your your pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.9.RELEASE</version>
<scope>test</scope>
</dependency>
Since you are going though the tutorials I'm assuming you are new to spring.
The folks at spring were nice enough to setup a site that generates projects.
It is very easy to use. I recommend trying that while learning. Download a few apps with the dependencies you want and look at how they are set up.
Once you are comfortable and want to dive deeper, read #glytching's answer again, it is very good.
Use spring-framework-bom if you don't use Spring Boot and need Spring Framework dependencies only:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.3.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
In such case dependency would be without version was specified:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
Also, yet another option exists if you use Spring Boot but you don't want to use spring-boot-starter-parent as parent artifact:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
See Spring Boot docs for more details. An important note from the docs:
Each release of Spring Boot is associated with a base version of the Spring Framework so we highly recommend you to not specify its version on your own.
It means that you should use Spring Framework version is defined for Spring Boot.
I want to add hibernate-spatial and postgis to my Maven project.
This is my pom.xml:
<properties>
<hibernate.version>4.3.6.Final</hibernate.version>
<hibernate.spatial.version>4.3</hibernate.spatial.version>
<hibernate.core.version>4.3.6.Final</hibernate.core.version>
<postgis-jdbc.version>2.2.0</postgis-jdbc.version>
</properties>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.core.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-entitymanager.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>${hibernate.spatial.version}</version>
</dependency>
<dependency>
<groupId>org.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
<version>${postgis-jdbc.version}</version>
</dependency>
The references to entity-manager and hibernate-core work. But hibernate-spatial and postgis-jdbc are not found:
org.hibernate:hibernate-spatial:4.3 not found Inspect a Maven model
for resolution problems.
(same error for postgis-jdbc)
How can I include these libraries in my project?
The library hibernate-spatial is not available in the public maven repository until 5.0. You can always check what is available by browsing http://mvnrepository.com/ (in this case http://mvnrepository.com/artifact/org.hibernate/hibernate-spatial).
But you can add the hibernate spatial repository to your POM, which contains earlier releases of hibernate-spatial:
<project ...>
...
<repositories>
<repository>
<id>Hibernate Spatial repo</id>
<url>http://www.hibernatespatial.org/repository</url>
</repository>
</repositories>
</project>
This contains the matching postgis-jdbc library in version 1.5.2 as well.