Spring boot 2.5.1 #AutoConfigureMockMvc doesn't load RouterFunctionMapping - java

I've upgraded my spring boot from version 2.3.3 to version 2.5.1 and it causes a test with
#SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
#AutoConfigureMockMvc
configuration to fail with 404 instead of 200
After comparing the logs what I found out that before the upgrade log contained the mapping:
2021-07-19 21:00:48.881 INFO 15114 --- [ Test worker] o.s.w.s.f.support.RouterFunctionMapping : Mapped /api => {
(GET && /ping) -> org.springframework.web.servlet.function.RouterFunctionDslKt$sam$org_springframework_web_servlet_function_HandlerFunction$0#22cf59c1
}
and after the upgrade, I couldn't find any RouterFunctionMapping log, so I guess it's probably related.
If it helps I defined the router using Kotlins RouterFunctionDsl.
I've tried looking for other questions and even to look for breaking changes, but I couldn't find any hint.

OK, seems that the problem is that for some reason, it can't find the endpoint unless I add a trailing slash to the mockMvc.perform call, very weird.

Related

ProbeEndpointsStrategy: Duplicate endpoints for id 'httptrace' detected. Omitting (same with 'threaddump')

Small question regarding SpringBoot Admin and a rather strange log I do not know how to fix.
My current setup is:
SpringBoot Admin Server 2.3.1
SpringBoot 2.4.0 (with actuator)
Spring Cloud Ilford (with Spring Cloud Kubernetes)
On a very simple SBA app:
#EnableScheduling
#EnableAdminServer
#EnableDiscoveryClient
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
I am getting the following when deployed on Kubernetes (tried Minikube, eks, gks, all have this issue).
However, it is not reproducible running on localhost.
2020-11-xx WARN [,,,] 47 --- [or-http-epoll-1] d.c.b.a.s.s.e.ProbeEndpointsStrategy : Duplicate endpoints for id 'httptrace' detected. Omitting: [ProbeEndpointsStrategy.DetectedEndpoint(definition=ProbeEndpointsStrategy.EndpointDefinition(id=httptrace, path=httptrace), endpoint=Endpoint(id=httptrace, url=http://{some wrong ip here}:8000/actuator/httptrace))]
2020-11-xx WARN [,,,] 47 --- [or-http-epoll-1] d.c.b.a.s.s.e.ProbeEndpointsStrategy : Duplicate endpoints for id 'threaddump' detected. Omitting: [ProbeEndpointsStrategy.DetectedEndpoint(definition=ProbeEndpointsStrategy.EndpointDefinition(id=threaddump, path=threaddump), endpoint=Endpoint(id=threaddump, url=http://{some wrong ip here}:8000/actuator/threaddump))]
The issue:
the IPs are incorrect
the port is an incorrect port, there is nothing on port 8000
my httptrace and threaddump are not under actuator/xxx
My actuator endpoints are all under /
management.endpoints.web.base-path=/
management.endpoints.web.exposure.include=*
May I ask what is the root cause of this, or is there any property needed to be configured in order to fix this?
This issue has been fixed with the latest Spring Boot 2.5.2 and Spring Boot admin 2.5.2

Unsupported partitioner with Amazon Keyspaces (for Apache Cassandra)

I have a Java Spring app and I'm using Amazon Keyspaces (for Apache Cassandra). I'm using the sigv4 plugin , (version 4.0.2), the cassandra java-driver-core (version 4.4.0) and have followed the official documentation on how to connect my java app with MCS. The app connects just fine but I'm getting a weird warning at start up:
WARN 1 --- [ s0-admin-0] .o.d.i.c.m.t.DefaultTokenFactoryRegistry : [s0] Unsupported partitioner 'com.amazonaws.cassandra.DefaultPartitioner', token map will be empty.
Everything looks good but after a few minutes that warning comes back and my queries start to fail. This is how the logs look after a few minutes:
WARN 1 --- [ s0-admin-0] .o.d.i.c.m.t.DefaultTokenFactoryRegistry : [s0] Unsupported partitioner 'com.amazonaws.cassandra.DefaultPartitioner', token map will be empty.
WARN 1 --- [ s0-io-1] c.d.o.d.i.c.m.SchemaAgreementChecker : [s0] Unknown peer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, excluding from schema agreement check
WARN 1 --- [ s0-io-0] c.d.o.d.i.c.control.ControlConnection : [s0] Unexpected error while refreshing schema after a successful reconnection, keeping previous version (CompletionException: com.datastax.oss.driver.api.core.connection.ClosedConnectionException: Channel was force-closed)
WARN 1 --- [ s0-io-1] c.d.o.d.i.c.m.DefaultTopologyMonitor : [s0] Control node ec2-x-xx-xxx-xx.us-east-2.compute.amazonaws.com/x.xx.xxx.xxx:xxxx has an entry for itself in system.peers: this entry will be ignored. This is likely due to a misconfiguration; please verify your rpc_address configuration in cassandra.yaml on all nodes in your cluster.
I have debugged a little and it looks like that partitioner comes from the actual node metadata, so I don't really know if there's an actual way to fix it.
I've seen there's a similar question asked recently here, but no solution has been posted yet. Any ideas? Thanks so much in advance
These are all warnings and not errors. Your connection should work just fine. They are logged due to how Amazon Keyspaces is slightly different from an actual Cassandra cluster. Try setting these to get rid of the noise:
datastax-java-driver.advanced {
metadata {
schema.enabled = false
token-map.enabled = false
}
connection.warn-on-init-error = false
}
Problem the same with me.
The above problems encountered when using a Spring boot version 2.3.x
Because is a Spring boot version 2.3.x
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra-reactive</artifactId>
</dependency>
OR
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
When creating a Maven / Gradle will get "datastax-java-driver-core 4.6.1" and I think this is another reason that Amazon Keyspaces are not supported.
Okay, Clear.....
Back to the subject of AWS library aws-sigv4-auth-cassandra-java-driver-plugin 4.0.2
When creating a Maven / Gradle will get "datastax-java-driver-core 4.4.0"
Now I am starting to see that Amazon Keyspaces
Maybe not supported "datastax-java-driver-core" with version greater than 4.4.0
Okay, it's been very long.
If you want Application Spring Boot 2 to work
You try following the solutions follows.
look at pom.xml
remove aws-sigv4-auth-cassandra-java-driver-plugin
downgrade Spring boot version 2.3.x to 2.2.9
add dependency below,
spring-boot-starter-data-cassandra-reactive
OR
spring-boot-starter-data-cassandra
create Amazon digital certificate and download
If you used InteljiJ IDEA Edit Configurations
Goto Edit Configurations -> next VM Options add below,
-Djavax.net.ssl.trustStore=path_to_file/cassandra_truststore.jks
-Djavax.net.ssl.trustStorePassword=my_password
Reference: https://docs.aws.amazon.com/keyspaces/latest/devguide/using_java_driver.html
application-dev.yml add config below,
spring:
data:
cassandra:
contact-points:
- "cassandra.ap-southeast-1.amazonaws.com"
port: 9142
ssl: true
username: "cassandra-username"
password: "cassandra-password"
keyspace-name: keyspace-name
request:
consistency: local_quorum
Run Test Program
Pass.
Work for me.
Tech Stack
Spring Boot WebFlux 2.2.9.RELEASE
Cassandra Reactive
JDK 13
Cassandra Database with Amazon Keyspaces
Maven 3.6.3
Have fun with programming.

Spring boot actuator endpoints.enabled=false endpoints.health.enabled=true

I am working on enabling spring boot health check using actuator. Since our app is dependent on Spring 1.5.21, so I have to use actuator 1.5.21 release. I read some configurations on their online documentation shows that you can apply the following to only allow "/health" endpoint to expose.
By default, all endpoints except for shutdown are enabled. If you prefer to specifically “opt-in” endpoint enablement you can use the endpoints.enabled property. For example, the following will disable all endpoints except for info:
endpoints.enabled=false
endpoints.info.enabled=true
Since I need to disable all endpoints except "/health" endpoint, so I configured it in application.properties file like below. However, it is not working for me.
endpoints.enabled=false
endpoints.health.enabled=true
Here is the result:
http://localhost:8080/health
{"message":"This endpoint is disabled"}
Environments:
Spring boot: 1.5.21 release
JDK: 1.8
Application: web application
Any thoughts on this? Thanks in advance!
UPDATES:
After I started a new project using the same spring boot 1.5.21.RELEASE, below settings worked.
endpoints.enabled=false
endpoints.health.enabled=true
2020-03-29 19:29:15.541 INFO 9796 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)
UPDATE on 3/30:
HOWEVER, when I used it with SDL Tridion 8.5, it stopped working. Any ideas?
<dependency>
<groupId>com.sdl.dxa</groupId>
<artifactId>dxa-common-api</artifactId>
<version>${dxaversion}</version>
</dependency>
<dependency>
<groupId>com.sdl.dxa</groupId>
<artifactId>dxa-common</artifactId>
<version>${dxaversion}</version>
</dependency>
<dependency>
<groupId>com.sdl.dxa</groupId>
<artifactId>dxa-tridion-provider</artifactId>
<version>${dxaversion}</version>
</dependency>
<dependency>
<groupId>com.sdl.dxa.modules</groupId>
<artifactId>dxa-module-core</artifactId>
<version>${dxaversion}</version>
</dependency>
endpoints.enabled=false
endpoints.health.enabled=true
Result:
http://localhost:8080/health
{"message":"This endpoint is disabled"}
No need to use disable. Use only below properties:
management.endpoints.web.exposure.include='health'

Spring boot Could not locate PropertySource: label not found

I am trying set Spring Cloud Config Server, but the service config server, it the running on port 8888 which is correct, and another service should run on port 18060, but for reason when I startup, it allocate port 8080 for me and the return a warning "Could not locate PropertySource: label not found", what should I do? Thank you !!!
Add #EnableConfigServer at configuration class level or main class of spring boot application and restart the service .it will work .
In my case it was because I had to set the default branch of my github URI (the branch of the repository set for spring.cloud.config.server.git.uri) in the config server by setting the following to the application.properties
spring.cloud.config.server.git.default-label=main
I ran into similar issue, when I run my server locally I see in the logs only on the stratup
o.s.c.c.c.ConfigServicePropertySourceLocator - Could not locate PropertySource: label not found
It turned out this is a problem with the health check for the config server, when health check is triggered to config server an empty environment is used so the application name is empty hence the spring cloud client will try to access {config-server}/application since application is the default application name, see issue for more info on this.
To solve the issue I just disabled the health check for config server
health.config.enabled=false
Try this one. I had the same issue and solved.
First enable debug mode in your app.(In your property file: logging.level.=DEBUG . This is only to make sure the issue is same as mine Or you may have any clue of where it can go wrong.)
Then start the application and see the logs. The log shows the configured server URI and what the URL to get all property resources.
Compare both URL s - the one in the log and your Configuration server URI.
Issue is that mistakenly the URL defined the property file can have empty space at the end. (This can happen when you copy past from somewhere ) Example:
the value for spring.cloud.config.uri=http:localhost:< port >< additional empty space >
If this is the case, the client's log shows localhost:/20%20%/ < app name > / < profile >
Simply remove the post empty space. Then it should work !
In your bootstrap.yml file
Add these lines
spring:
cloud:
config:
enabled: true
uri: http://localhost:8888 ##this is the link to the server config
label: main ##this is what you are missing (name of the git repo branch)
application:
name: currency-spring-cloud-config-client
profiles:
active: testing
server:
port: 8600
spring:
cloud:
config:
enabled: true
uri:
- http://localhost:9196 ### your port for cloud config server
label: main ### your git repo branch name
In my case my server was fetching cofnigs from github repository, and I forgot that I made it private :)

Activiti + Spring Boot + Gradle build hangs while gradle clean test

I am having an issue with executing gradle clean test command.
My application is using activiti for workflow.
Git url: https://github.com/sanelib/eBOSS/tree/merge-before-dev
Branch: "merge-before-dev" is having more tests for activiti worflow process. But it execute only 6 of 12 integration tests from "core" module. If I use #Ignore to any random 6 tests then it success for rest 6. I have put some console out to debug and found it hangs on starting activiti process.
This source has also included database schema in /scripts folder. Let me know if you miss any required file for testing in your environment.
Can anybody look into this and give me solution?
I got also result: 23 tests completed, 14 failed :core:test FAILED
Than I randomly picked one of your tests and it failed in isolation also. It doesn't seem to be concurrency problem.
Root cause seem to be this:
2016-02-05 20:56:16.556 WARN 16072 --- [ main] o.h.e.jdbc.internal.JdbcServicesImpl : HHH000342: Could not obtain connection to query metadata : Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
Place break-point on this line in Hibernate.
So it does seem to be connection problem.

Categories