I have a problem about running the URLs shown below.
http://localhost:8041/users-ws/users/status/check (run)
http://localhost:8041/users/status/check (not run)
What I want to do is to run all these URL but only the first one runs.
How can I run both URLs?
How can I revise application properties file?
Here is my code snippet shown below in application.properties file in Spring Cloud API Gateway
server.port=8041
spring.application.name=api-gateway
eureka.client.service-url.defaultZone=http://localhost:8040/eureka
spring.cloud.gateway.routes[0].id=users-status-check
spring.cloud.gateway.routes[0].uri = lb://users-ws
spring.cloud.gateway.routes[0].predicates[0]=Path=/users-ws/users/status/check
spring.cloud.gateway.routes[0].predicates[1]=Method=GET
spring.cloud.gateway.routes[0].filters[0]=RemoveRequestHeader=Cookie
spring.cloud.gateway.routes[0].filters[1]=RewritePath=/users-ws/(?<segment>.*), /$\{segment}
Could you post your user-ws controller?
Anyway, try that:
spring.cloud.gateway.routes[0].predicates[0]=Path=/users/**
looks like your application name is "users-ws", and your request mapping is "/users", in this case, is not necessary put your application name in the path but we need to see more code, to be honest.
Related
I'm a relatively new Java developer that is working on a Java 8 Spring Boot project. I am trying to learn and understand WebSockets so I have created a basic Websocket server that appears to be up and running correctly.
I wanted to use the Static folder to render a basic HTML page with a JS file and CSS. From what I have researched, it should use it automatically, but I'm getting a standard whitepage error when I use the browser to connect when my research seems to indicate it should render by default?
I've heard that Thymeleaf is used to render templates, but I have also read that I can connect a basic HTML file from the Static folder instead. When I try to connect to the main server, it gives me the following logs from my different attempts to see the index.......
No mapping for GET /
No mapping for GET /index
No mapping for GET /index.html
I'm not sure what the problem could be and my Google-Fu is turning up no solutions. I feel like I must be missing something fundamental here, but I'm not sure how to properly map that route. I have Spring Web dependencies installed so I could create a RestController mapping to that route, but how would I properly return those static files?
You need to create the endpoint for the default entry page of your application. Something like this:
#Controller
public class HomeController {
#GetMapping("/")
public String index() {
return "index";
}
}
Your index.html goes inside this path "src/main/resources/templates/".
The solution I found through another source on Discord..
Part of the problem was I was using #RestController instead of #Controller.
The other issue was I had my index.html in the public folder instead of Templates.
And the final error was I had the incorrect Thymeleaf dependency. I needed the Thymeleaf Starter and I had accidentally added a different one from Maven Repo.
I have created a custom spring-boot actuator health endpoint for my application. Spring boot aggregates all these custom health endpoints into a one big json and returns it when I hit application/health url. Now I want to pass some information to the custom health end point that I have implemented in form of a header when I hit the application/health url. How can I achieve this?
If you at all want to pass a header , you might consider hitting the API (a GET API in this case) from any RestClient like PostMan or Insomnia. Simply hitting the url from the browser is actually making a GET request but you can only add path or request parameters in the url, for adding a request body or headers,you will need to use a REST client, or alternatively do it from the command line using curl.
Also, after reading the comments,i think what you need is,is to set spring.profile property and determine your code flow based on that- here's how you can set the profile-
1) set Java System Properties (VM Arguments)
java -jar -Dspring.profiles.active=test myapp.jar
2) set Program arguments
java -jar application.jar --spring.profiles.active=test
I am using Spring Boot and have an issue related #Scheduled.
#Scheduled(fixedRateString = "${timeRate}")
public void SaveStatisticData() {
System.out.println("save Info per "+timeRate+"msec");
...
}
this is a part of my code. this method will run by timeRate value from properties and Properties File is connected with web API.
That means someone can request to change timeRate in Properties File.
I want to know how to reload spring boot on client request which change Properties File.
AFAIK, I can use Hot Swapping in spring boot.
But I think this solution is not good to service.
Because The service have to reload whenever a client request changing timeRate.
In other words, is there another way to apply this client request in real time?
I need to compose a spring controller (server side of course) for uploading files - when I get the file I need to run some validations.
The thing is - my clients may try to upload some really big file and I would like to run this validation based on a meta data they will supply.
What is the best practice for this?
What should be the resource they should run the validation against?
For example, the file resource may seem like this:
POST .../files
GET .../files/{id} or ../files to get all
DELETE ../files/{id}
Of course the validation will be in each method - but as I said before, I would like to enable the client to run the validation in a decoupled manner.
Thanks
I am using spring cloud config server to save all the configuration in various environments,upto now, it worked great, but now, I suddenly met an issue, don't knwo how to change it.
By default, the url pattern is: http://xxx.xx.xx:8888/{appName}/{environemnt}
But now I need to deploy multiple service together, and I can no longer use path to the root, and I need to use this one:
http://xxx.xxx.xx/pathToConfig/{appName}/{env}
But I noticed that spring config server will consider as appName instead there.
May I ask if there are any configuration I can change to make sure spring config server be able to consider url only after some path after the root?
Thanks
spring.cloud.config.server.prefix: /<path> only changes the prefix for the config server api, not the whole application.
You can specify server.contextPath: /pathToConfig in your application.yml of other configuration.
Then it will prefix all the mappings with the specified path.