I got error after upgrade the spring-web version to after 6.0.0, previous is 5.3.20
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.4</version>
</dependency>
Cannot access 'status': it is invisible (private in a supertype) in 'ResponseStatusException'
is ResponseStatusException -> {
serverWebExchange.response.statusCode = throwable.status
}
In spring 5.3.x ResponseStatusException used to have getStatus() available directly as you can see in the java doc https://docs.spring.io/spring-framework/docs/5.3.x/javadoc-api/
In version 6.0.x it was changed and ResponseStatusException extends from ErrorResponseException which does not have the getStatus() method directly available.
Instead, you need to call responseStatusException.getBody().getStatus() in order to access the status correctly. Check the java doc for details https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/ErrorResponseException.html
From your question it is not clear if you access status directly in your code or if this code is part of some library. If it is part of the library, then you would need to upgrade the version of the library to the one compatible with spring 6.
Related
I'd like to write some tests for particuar classes. Yet, I want to read in an EML file. This works fine by using
IOUtils.toString(r.getInputStream(), StandardCharsets.UTF_8);
I have a class which is (normally) able to read such an EML (by InputStream, filename or file content(String)) what is done so far in multiple places in the project. When I try to do this in a test class I get this:
java.lang.NoSuchMethodError: 'boolean com.sun.mail.util.PropUtil.getBooleanSessionProperty(javax.mail.Session, java.lang.String, boolean)'
at javax.mail.internet.MimeMessage.initStrict(MimeMessage.java:320)
at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:215)
at d.d.a.c.e.EmlFileHolder.buildByEmlFile(EmlFileHolder.java:103)
at d.d.a.c.e.EmlFileHolder.buildByEmlFileStream(EmlFileHolder.java:99)
at d.d.a.c.e.EmlFileHolder.buildByEmlFileString(EmlFileHolder.java:81)
Maybe a problem with the dependencies? (But I couldn't solve or even figure out the problem.) Here, the imported dependencies related to mail, MimeMessages, ...
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>${simple-java-mail.version}</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>smime-module</artifactId>
<version>${simple-java-mail.version}</version>
</dependency>
You appear to be mixing code that uses the old javax.mail.* APIs (and thus com.sun.mail.*) with the new jakarta.mail 2.0 API and implementation.
I suspect you managed this by updating to jakarta.mail in the POM but keeping ${simple-java-mail.version} at 6.7.x or earlier. (This is an inference. It is not clear from your question what version you are actually using.)
If you are going to use jakarta.mail 2.0 and later, you need to use simple-java-mail 7.0 or later.
Alternatively, you could wind back to an earlier version of javax.mail. (There are jakarta.mail 1.6.7 artifacts in Maven Central, but the are apparently just the corresponding javax.mail artifacts renamed.)
I am trying to configure spring session backed by hazelcast for spring security oauth2 client application.
I followed below link to configure hazelcast.
https://docs.spring.io/spring-session/docs/current/reference/html5/guides/java-hazelcast.html
However, classes annotated with #SpringBootTest started failing due to below error:
java.lang.IncompatibleClassChangeError: class org.springframework.session.hazelcast.PrincipalNameExtractor has interface com.hazelcast.query.extractor.ValueExtractor as super class
My pom.xml of spring boot 2.5 application contain below two new dependencies for hazelcast configuration
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-hazelcast</artifactId>
</dependency>
As per below stackoverflow post , issue seems to be that ValueExtractor is available for two different versions in maven dependencies
IncompatibleClassChangeError: class ClassMetadataReadingVisitor has interface ClassVisitor as super class
Hence, I checked maven dependencies and can see that PrincipalNameExtractor is available from 2.5 version of spring-session-hazelcast while ValueExtractor is available from 4.2 version on com.hazelcast. However,
spring-session-hazelcast is using 3.12.12 version of com.hazelcast for compilation.
So should I use 3.12.12 version of com.hazelcast to resolve this issue or am in misinterpreting the issue? I prefer to use latest version.
Starting from spring-sessions v2.4.0, you can use Hazelcast v4.x with configuring Hazelcast4PrincipalNameExtractor and Hazelcast4IndexedSessionRepository for the session repository. The only difference is the class names with 4 indicator. That is, HazelcastIndexedSessionRepository becomes 4.x compatible with Hazelcast4IndexedSessionRepository.
Here is a guide covering both versions: https://guides.hazelcast.org/spring-session-hazelcast/
I have been stuck with this issue for a while now and any assistance is appreciated. I am running Spring Boot version 2.2.0 with the ElasticSearch high-level REST Client version 6.4.3 and using version 3.2.0 for the Spring-Data-Elasticsearch version. I am getting the error below. I have tried the following attempts to fix but none do.
Change Spring Boot Version multiple times
Change ES version multiple times
I have cleared my .m2 folder and redownloaded the maven dependencies multiple times.
The issue I am getting below is
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.putMapping(ElasticsearchRestTemplate.java:292)
The following method did not exist:
org.elasticsearch.client.IndicesClient.putMapping(Lorg/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest;Lorg/elasticsearch/client/RequestOptions;)Lorg/elasticsearch/action/support/master/AcknowledgedResponse;
The method's class, org.elasticsearch.client.IndicesClient, is available from the following locations:
jar:file:/Users/user/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.3/elasticsearch-rest-high-level-client-6.4.3.jar!/org/elasticsearch/client/IndicesClient.class
It was loaded from the following location:
file:/Users/user/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.3/elasticsearch-rest-high-level-client-6.4.3.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.IndicesClient
My POM is below
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.2.0</version>
</dependency>
Any help is appreciated. I am sure it has to deal with compatibility issues but not sure which. Thanks all!
Update
I was able to get it run sucessfully by changing my elasticsearch version to 6.7.0. But now I am receiving the following error
org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=index_not_found_exception, reason=no such index]
My POM looks like this below now also.
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.70</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.70</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>6.70</version>
</dependency>
Previous issue of method that does not exist. was resolved by changing the elasticsearch version to 6.7.0.
To avoid these incompatibility issues its always recommend to use the same version of elasticsearch server and its client.
I faced the exact same issue, I was using elastic search 6.8.18.
and as mentioned changed the version of elastic search by using below in Gradle.
ext['elasticsearch.version'] = '6.8.18'
use this for reference - overriding dependency versions
I have a Maven Java project that uses Mashape Unirest for sending HTTP requests to other URLs. I am currently writing an integration test (using TestNG) that sends a normal HTTP request using Unirest. When I run the integration test through Maven (via the Failsafe plugin), the request is sent out successfully. However, when I try to run the integration test via Eclipse, I keep on getting the following error:
FAILED: getCurrentTimeTest
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:487)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:147)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:136)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:112)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
at com.mashape.unirest.http.options.Options.refresh(Options.java:41)
at com.mashape.unirest.http.options.Options.<clinit>(Options.java:27)
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:141)
at com.mashape.unirest.http.HttpClientHelper.requestAsync(HttpClientHelper.java:80)
at com.mashape.unirest.request.BaseRequest.asStringAsync(BaseRequest.java:56)
at ...
I am also able to reproduce this error using a basic Java application script.
I have made sure that the dependencies I am using in my pom.xml file are the latest and greatest, as seen below:
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.2</version>
</dependency>
I have also checked out the source code of BasicLineFormatter.java, both from the source file downloaded to Eclipse and from Apache's Httpcore Github repo. In the Github repo, notice how the INSTANCE field is defined for the 4.3.x branch and the trunk branch, but not in older branches like 4.2.x. However, I am indeed using version 4.3.2 in my project, so I should be using a JAR file for Httpcore that has the latest version of BasicLineFormatter. I know that, based on the Maven Dependencies JAR files that are in my project, that I am indeed using the latest versions of these Apache dependencies, not the older versions specified as downstream dependencies of my project.
I have checked other various SOF and blog posts about this issue, such as Mashape Unirest Java : java.lang.NoClassDefFoundError and this blog post too, but they all seem to be talking about solving the NoSuchFieldError problem for Android. However, I'm dealing with a standalone Java application, not an Android application.
I am at a loss in determining how to troubleshoot this issue. Anyone have any idea what I need to do?
UPDATE
Instead of showing my test case, I will reduce the illustration of a reproduction of this problem to just a simple one-liner Java application, because the problem exists with any Java application or test case run through Eclipse, not just one particular test:
System.out.println(Unirest.get("http://www.google.com").asStringAsync().get().getBody());
Normally, this should print the HTML of the Google home page, but I instead get the NoSuchFieldError stack trace.
FIXED!
The problem was that the AWS SDK (it's on my classpath because I'm developing for Elastic Beanstalk) had a conflicting JAR file. Using Oleg's solution (thanks BTW), I printed the following output in a unit test:
jar:file:/some/path/aws-java-sdk/1.7.1/third-party/httpcomponents-client-4.2.3/httpcore-4.2.jar!/org/apache/http/message/BasicLineFormatter.class
I'll have to rearrange my classpath so that AWS SDK is no longer conflicting.
The only plausible explanation to this problem is there is an older version of HttpCore on the classpath (unless you also want to consider a possibility of green men from Mars messing with your computer remotely from a flying saucer).
You can add this snippet to your code to find out what jar the class gets picked up from. This might help find out why that jar is on your classpath in the first place.
ClassLoader classLoader = MyClass.class.getClassLoader();
URL resource = classLoader.getResource("org/apache/http/message/BasicLineFormatter.class");
System.out.println(resource);
This basically tells me that in my case the jar resides in the local maven repository and likely to have been added to the classpath by Maven
jar:file:/home/oleg/.m2/repository/org/apache/httpcomponents/httpcore/4.3.1/httpcore-4.3.1.jar!/org/apache/http/message/BasicLineFormatter.class
As already mentioned by previous comments, It's mainly because of the conflicting versions of httpcore jar, the static field INSTANCE is been added to BasicLineFormatter class in versions > 4.3.1, Though you might have added the latest version of the httpcore jar in your dependencies, but its highly possible that other (lower) version of jar is getting picked up.
So, first to confirm that, wrong jar is getting picked up, Use the following line of code -
ClassLoader classLoader = <Your Class>.class.getClassLoader();
URL resource = classLoader.getResource("org/apache/http/message/BasicLineFormatter.class");
System.out.println(resource);
If this prints, the lower version of the jar, then it's confirmed that it's picking the lower version of the httpcore jar (May be from other dependencies of your project),
Solution -
Add following maven/gradle dependencies at the top of dependency list (Or above the other project dependency which caused the conflict) -
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
</dependency>
I faced the same exception using unirest:
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at com.mashape.unirest.http.options.Options.refresh(Options.java:55)
at com.mashape.unirest.http.options.Options.<clinit>(Options.java:36)
And found it was due to DefaultConnectionKeepAliveStrategy.INSTANCE; and the conflicting jar was apache-httpcomponents-httpclient.jar in my classpath. Adding this post to help anyone who faces similar exception
I got this Exception: Caused by: java.lang.NoSuchFieldError: INSTANCE
Solution:
This happens if you have two different version classes in your classpath…. […], So I first find that class (one version of class), click that class, select build path, then I click remove from build path.
if you are using aws sdk this error occurs because of dependency mismatch.
To avoid this error do the following:
1.Put the dependecies in the required order aws sdk and the end preferably
2.Add shade plugin to the project
This solved my problem
you can refer to my answer in
HTTPClient Example - Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
my case is i have httpclient-4.4.1.jar, and httpcore-4.4.1.jar in my class path, but JVM loaded BasicLineFormatter from httpcore-4.0.jar
I used to use neo4j-community-1.9.4 with my java maven project. I switched to version 2.0 and made completly new db in 2.0. When I run the same java code, I get error:
Exception in thread "main" org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException: Failed to start Neo4j with an older data store version. To enable automatic upgrade, please set configuration parameter "allow_store_upgrade=true"
at org.neo4j.kernel.impl.storemigration.ConfigMapUpgradeConfiguration.checkConfigurationAllowsAutomaticUpgrade(ConfigMapUpgradeConfiguration.java:39)
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.attemptUpgrade(StoreUpgrader.java:64)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.tryToUpgradeStores(StoreFactory.java:104)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.newNeoStore(StoreFactory.java:86)
at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.<init>(NeoStoreXaDataSource.java:232)
at org.neo4j.kernel.InternalAbstractGraphDatabase.create(InternalAbstractGraphDatabase.java:423)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:226)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:79)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:70)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:205)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:56)
at tools.Import.main(Import.java:32)
Any idea? Thank you.
Neo4j 2.0 requires an explicit store upgrade, because older versions will no longer be able to run on the upgraded store. The exception mentions this:
Failed to start Neo4j with an older data store version. To enable automatic upgrade, please set configuration parameter "allow_store_upgrade=true"
Simply add allow_store_upgrade=true to your neo4j.properties file, and start the database again. Then it should do the upgrade. You can read more about this here:
http://docs.neo4j.org/chunked/stable/deployment-upgrading.html#explicit-upgrade
Solved, I replaced dependency from spring:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
By this:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.0.0</version>
</dependency>
For community edition on windows,
click on Options, Database Configuration, Edit
look for allow_store_upgrade